Skip to content

Commit

Permalink
add crate feature "nightly" to enable features in rust nightly
Browse files Browse the repository at this point in the history
- enables code using cow_is_borrowed
- enables code using new_uninit

- use Vec::chunk_by (stable since rust 1.70)
- use divan for benchmarks
- add function to create empty vec
  • Loading branch information
alexander-buerger-met-no committed Jul 3, 2024
1 parent 6a28be8 commit 8bc384e
Show file tree
Hide file tree
Showing 23 changed files with 398 additions and 266 deletions.
80 changes: 80 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ features = ["sync", "macros", "rt-multi-thread"]
version = "1"

[dev-dependencies]
divan = "0.1.14"
rand = "0.8"
sled = "0.34.6"
reqwest = { version = "0.11", features = [ "blocking" ] }
Expand All @@ -71,4 +72,40 @@ fast-index = []
python = ["pyo3", "numpy"]
extension-module = ["python", "pyo3/extension-module"]
netcdf = [ "dep:netcdf" ]
unstable = []

[[bench]]
name = "concurrency"
harness = false

[[bench]]
name = "dataset"
harness = false

[[bench]]
name = "index"
harness = false

[[bench]]
name = "large"
harness = false

[[bench]]
name = "native"
harness = false

[[bench]]
name = "norkyst"
harness = false

[[bench]]
name = "read"
harness = false

[[bench]]
name = "serialize"
harness = false

[[bench]]
name = "stream"
harness = false
48 changes: 25 additions & 23 deletions benches/concurrency.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![feature(test)]
extern crate test;
use std::sync::Arc;
use test::Bencher;
use divan::Bencher;

use hidefix::prelude::*;

Expand Down Expand Up @@ -30,64 +28,64 @@ mod shuffled_compressed {
use super::*;

#[ignore]
#[bench]
fn cache_sequential(b: &mut Bencher) {
#[divan::bench]
fn cache_sequential(b: Bencher) {
let i = Index::index("tests/data/dmrpp/chunked_shufzip_twoD.h5").unwrap();
let mut r = i.reader("d_4_shufzip_chunks").unwrap();

b.iter(|| {
b.bench_local(|| {
for _ in 0..ITERATIONS {
for _ in 0..REPETITIONS {
test::black_box(&r.values::<f32, _>(..).unwrap());
divan::black_box(&r.values::<f32, _>(..).unwrap());
}
}
})
}

#[ignore]
#[bench]
fn direct_sequential_parallel(b: &mut Bencher) {
#[divan::bench]
fn direct_sequential_parallel(b: Bencher) {
let i = Index::index("tests/data/dmrpp/chunked_shufzip_twoD.h5").unwrap();
let ds = i.dataset("d_4_shufzip_chunks").unwrap();
let r = ds
.as_par_reader(&"tests/data/dmrpp/chunked_shufzip_twoD.h5")
.unwrap();

b.iter(|| {
b.bench_local(|| {
for _ in 0..ITERATIONS {
for _ in 0..REPETITIONS {
test::black_box(&r.values_par::<f32, _>(..).unwrap());
divan::black_box(&r.values_par::<f32, _>(..).unwrap());
}
}
})
}

#[ignore]
#[bench]
fn native_sequential(b: &mut Bencher) {
#[divan::bench]
fn native_sequential(b: Bencher) {
let h = hdf5::File::open("tests/data/dmrpp/chunked_shufzip_twoD.h5").unwrap();
let d = h.dataset("d_4_shufzip_chunks").unwrap();

b.iter(|| {
b.bench_local(|| {
for _ in 0..ITERATIONS {
for _ in 0..REPETITIONS {
test::black_box(&d.read_raw::<f32>().unwrap());
divan::black_box(&d.read_raw::<f32>().unwrap());
}
}
})
}

#[ignore]
#[bench]
fn cache_concurrent_reads(b: &mut Bencher) {
#[divan::bench]
fn cache_concurrent_reads(b: Bencher) {
let i = Arc::new(Index::index("tests/data/dmrpp/chunked_shufzip_twoD.h5").unwrap());

let pool = rayon::ThreadPoolBuilder::new()
.num_threads(8)
.build()
.unwrap();

b.iter(move || {
b.bench_local(move || {
let i = Arc::clone(&i);
pool.scope(move |s| {
for _ in 0..ITERATIONS {
Expand All @@ -96,7 +94,7 @@ mod shuffled_compressed {
s.spawn(move |_| {
let mut r = i.reader("d_4_shufzip_chunks").unwrap();
for _ in 0..REPETITIONS {
test::black_box(&r.values::<f32, _>(..).unwrap());
divan::black_box(&r.values::<f32, _>(..).unwrap());
}
});
}
Expand All @@ -105,8 +103,8 @@ mod shuffled_compressed {
}

#[ignore]
#[bench]
fn native_concurrent_reads(b: &mut Bencher) {
#[divan::bench]
fn native_concurrent_reads(b: Bencher) {
let h = hdf5::File::open("tests/data/dmrpp/chunked_shufzip_twoD.h5").unwrap();
let d = Arc::new(h.dataset("d_4_shufzip_chunks").unwrap());

Expand All @@ -115,19 +113,23 @@ mod shuffled_compressed {
.build()
.unwrap();

b.iter(move || {
b.bench_local(move || {
let d = Arc::clone(&d);
pool.scope(move |s| {
for _ in 0..ITERATIONS {
let d = Arc::clone(&d);

s.spawn(move |_| {
for _ in 0..REPETITIONS {
test::black_box(&d.read_raw::<f32>().unwrap());
divan::black_box(&d.read_raw::<f32>().unwrap());
}
});
}
})
})
}
}

fn main() {
divan::main();
}
14 changes: 8 additions & 6 deletions benches/dataset.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#![feature(test)]
extern crate test;
use test::Bencher;
use divan::Bencher;

use hidefix::idx::DatasetD;
use hidefix::idx::Index;

#[bench]
fn slicer(b: &mut Bencher) {
#[divan::bench]
fn slicer(b: Bencher) {
let i = Index::index("tests/data/coads_climatology.nc4").unwrap();
let d = i.dataset("SST").unwrap();
if let DatasetD::D3(d) = d {
b.iter(|| d.chunk_slices(..).for_each(drop))
b.bench_local(|| d.chunk_slices(..).for_each(drop))
} else {
panic!()
}
}

fn main() {
divan::main();
}
14 changes: 8 additions & 6 deletions benches/index.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#![feature(test)]
extern crate test;
use test::Bencher;
use divan::Bencher;

use hidefix::idx::Index;

#[bench]
fn chunked_1d(b: &mut Bencher) {
b.iter(|| Index::index("tests/data/dmrpp/chunked_oneD.h5").unwrap())
#[divan::bench]
fn chunked_1d(b: Bencher) {
b.bench_local(|| Index::index("tests/data/dmrpp/chunked_oneD.h5").unwrap())
}

fn main() {
divan::main();
}
Loading

0 comments on commit 8bc384e

Please sign in to comment.