Skip to content

Commit

Permalink
bench: fix large benches
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Aug 16, 2023
1 parent 6e6c14d commit 0315dc3
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions benches/large.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use std::path::PathBuf;
use std::sync::Mutex;

use hidefix::prelude::*;
use ndarray::s;
use ndarray::{s, Dim, IxDyn};

const URL: &'static str = "https://thredds.met.no/thredds/fileServer/fou-hi/norkyst800m-1h/NorKyst-800m_ZDEPTHS_his.an.2023081600.nc";
const VAR: &'static str = "u_eastward";

type T = f32;

fn get_file() -> PathBuf {
use std::time::Duration;

Expand Down Expand Up @@ -49,21 +51,21 @@ fn idx_small_slice(b: &mut Bencher) {
let h = hdf5::File::open(&p).unwrap();
let d = h.dataset(VAR).unwrap();
let hv = d
.read_slice_1d::<i32, _>(s![0..2, 0..2, 0..1, 0..5])
.read_slice::<T, _, IxDyn>(s![0..2, 0..2, 0..1, 0..5])
.unwrap()
.iter()
.map(|v| *v)
.collect::<Vec<i32>>();
.collect::<Vec<T>>();

assert_eq!(
hv,
r.values::<i32>(Some(&[0, 0, 0, 0]), Some(&[2, 2, 1, 5]))
r.values::<T>(Some(&[0, 0, 0, 0]), Some(&[2, 2, 1, 5]))
.unwrap()
);

b.iter(|| {
test::black_box(
r.values::<i32>(Some(&[0, 0, 0, 0]), Some(&[2, 2, 1, 5]))
r.values::<T>(Some(&[0, 0, 0, 0]), Some(&[2, 2, 1, 5]))
.unwrap(),
)
});
Expand All @@ -78,7 +80,7 @@ fn native_small_slice(b: &mut Bencher) {

b.iter(|| {
test::black_box(
d.read_slice_1d::<i32, _>(s![0..2, 0..2, 0..1, 0..5])
d.read_slice::<T, _, IxDyn>(s![0..2, 0..2, 0..1, 0..5])
.unwrap(),
)
})
Expand All @@ -95,21 +97,21 @@ fn idx_med_slice(b: &mut Bencher) {
let h = hdf5::File::open(&p).unwrap();
let d = h.dataset(VAR).unwrap();
let hv = d
.read_slice_1d::<i32, _>(s![0..10, 0..10, 0..1, 0..700])
.read_slice::<T, _, IxDyn>(s![0..10, 0..10, 0..1, 0..700])
.unwrap()
.iter()
.map(|v| *v)
.collect::<Vec<i32>>();
.collect::<Vec<T>>();

assert_eq!(
hv,
r.values::<i32>(Some(&[0, 0, 0, 0]), Some(&[10, 10, 1, 700]))
r.values::<T>(Some(&[0, 0, 0, 0]), Some(&[10, 10, 1, 700]))
.unwrap()
);

b.iter(|| {
test::black_box(
r.values::<i32>(Some(&[0, 0, 0, 0]), Some(&[10, 10, 1, 700]))
r.values::<T>(Some(&[0, 0, 0, 0]), Some(&[10, 10, 1, 2602]))
.unwrap(),
)
});
Expand All @@ -124,7 +126,7 @@ fn native_med_slice(b: &mut Bencher) {

b.iter(|| {
test::black_box(
d.read_slice_1d::<i32, _>(s![0..10, 0..10, 0..1, 0..20000])
d.read_slice::<T, _, IxDyn>(s![0..10, 0..10, 0..1, 0..2602])
.unwrap(),
)
})
Expand All @@ -141,21 +143,21 @@ fn idx_big_slice(b: &mut Bencher) {
let h = hdf5::File::open(&p).unwrap();
let d = h.dataset(VAR).unwrap();
let hv = d
.read_slice_1d::<i32, _>(s![0..24, 0..16, 0..1, 0..739])
.read_slice::<T, _, IxDyn>(s![0..24, 0..16, 0..1, 0..739])
.unwrap()
.iter()
.map(|v| *v)
.collect::<Vec<i32>>();
.collect::<Vec<T>>();

assert_eq!(
hv,
r.values::<i32>(Some(&[0, 0, 0, 0]), Some(&[24, 16, 1, 739]))
r.values::<T>(Some(&[0, 0, 0, 0]), Some(&[24, 16, 1, 739]))
.unwrap()
);

b.iter(|| {
test::black_box(
r.values::<i32>(Some(&[0, 0, 0, 0]), Some(&[24, 16, 1, 739]))
r.values::<T>(Some(&[0, 0, 0, 0]), Some(&[24, 16, 1, 2602]))
.unwrap(),
)
});
Expand All @@ -170,7 +172,7 @@ fn native_big_slice(b: &mut Bencher) {

b.iter(|| {
test::black_box(
d.read_slice_1d::<i32, _>(s![0..65, 0..65, 0..1, 0..20000])
d.read_slice::<T, _, IxDyn>(s![0..24, 0..16, 0..1, 0..2602])
.unwrap(),
)
})
Expand Down

0 comments on commit 0315dc3

Please sign in to comment.