Skip to content

Commit

Permalink
Fix benchmarks
Browse files Browse the repository at this point in the history
- Rename compete -> alts
- Merge impl into -> variants
- Re-group benchmarks to provide better comparision in generated criterion reports
- Remove zeros,ones data as the differences between them and random were almost zero
  • Loading branch information
mcountryman committed Jul 24, 2023
1 parent 0b8d6d9 commit f7ab310
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 436 deletions.
340 changes: 146 additions & 194 deletions Cargo.lock

Large diffs are not rendered by default.

33 changes: 4 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,13 @@ debug = true
opt-level = 2

[[bench]]
name = "all"
path = "bench/all.rs"
name = "alts"
path = "bench/alts.rs"
harness = false

[[bench]]
name = "avx2"
path = "bench/avx2.rs"
harness = false

[[bench]]
name = "avx512"
path = "bench/avx512.rs"
harness = false

[[bench]]
name = "scalar"
path = "bench/scalar.rs"
harness = false

[[bench]]
name = "sse2"
path = "bench/sse2.rs"
harness = false

[[bench]]
name = "ssse3"
path = "bench/ssse3.rs"
harness = false

[[bench]]
name = "compete"
path = "bench/compete.rs"
name = "variants"
path = "bench/variants.rs"
harness = false

[features]
Expand Down
18 changes: 0 additions & 18 deletions bench/all.rs

This file was deleted.

60 changes: 60 additions & 0 deletions bench/alts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use criterion::{
black_box, criterion_group, criterion_main, measurement::Measurement, BenchmarkGroup,
Criterion, Throughput,
};
use rand::{thread_rng, RngCore};

pub fn bench(c: &mut Criterion) {
let mut data = vec![0; 100_000];
let mut group = c.benchmark_group("alts");

thread_rng().fill_bytes(&mut data[..]);

bench_alt(&mut group, "adler", &data, |data| {
let mut adler = adler::Adler32::new();

adler.write_slice(data);
adler.checksum()
});

bench_alt(&mut group, "adler32", &data, |data| {
let mut adler = adler32::RollingAdler32::new();

adler.update_buffer(data);
adler.hash()
});

bench_alt(&mut group, "simd-adler32", &data, |data| {
let mut adler = simd_adler32::Adler32::new();

adler.write(data);
adler.finish()
});
}

fn bench_alt<M, F>(g: &mut BenchmarkGroup<M>, name: &str, data: &[u8], mut imp: F)
where
M: Measurement,
F: FnMut(&[u8]) -> u32,
{
g.throughput(Throughput::Bytes(10)).bench_with_input(
format!("{}-10b", name),
&data[..10],
|b, data| b.iter(|| black_box(imp(data))),
);

g.throughput(Throughput::Bytes(10_000)).bench_with_input(
format!("{}-10k", name),
&data[..10_000],
|b, data| b.iter(|| black_box(imp(data))),
);

g.throughput(Throughput::Bytes(100_000)).bench_with_input(
format!("{}-100k", name),
&data[..100_000],
|b, data| b.iter(|| black_box(imp(data))),
);
}

criterion_group!(benches, bench);
criterion_main!(benches);
22 changes: 0 additions & 22 deletions bench/avx2.rs

This file was deleted.

22 changes: 0 additions & 22 deletions bench/avx512.rs

This file was deleted.

64 changes: 0 additions & 64 deletions bench/compete.rs

This file was deleted.

20 changes: 0 additions & 20 deletions bench/scalar.rs

This file was deleted.

22 changes: 0 additions & 22 deletions bench/sse2.rs

This file was deleted.

22 changes: 0 additions & 22 deletions bench/ssse3.rs

This file was deleted.

23 changes: 0 additions & 23 deletions bench/util.rs

This file was deleted.

61 changes: 61 additions & 0 deletions bench/variants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use criterion::{
black_box, criterion_group, criterion_main, measurement::Measurement, BenchmarkGroup,
Criterion, Throughput,
};
use rand::{thread_rng, RngCore};
use simd_adler32::imp::{avx2, avx512, scalar, sse2, ssse3, wasm, Adler32Imp};

pub fn bench(c: &mut Criterion) {
let mut data = [0; 100_000];
let mut group = c.benchmark_group("variants");

thread_rng().fill_bytes(&mut data[..]);

if let Some(update) = avx512::get_imp() {
bench_variant(&mut group, "avx512", &data, update);
}

if let Some(update) = avx2::get_imp() {
bench_variant(&mut group, "avx2", &data, update);
}

if let Some(update) = ssse3::get_imp() {
bench_variant(&mut group, "ssse3", &data, update);
}

if let Some(update) = sse2::get_imp() {
bench_variant(&mut group, "sse2", &data, update);
}

if let Some(update) = wasm::get_imp() {
bench_variant(&mut group, "wasm", &data, update);
}

bench_variant(&mut group, "scalar", &data, scalar::update);
}

fn bench_variant<M>(g: &mut BenchmarkGroup<M>, name: &str, data: &[u8], imp: Adler32Imp)
where
M: Measurement,
{
g.throughput(Throughput::Bytes(10)).bench_with_input(
format!("{}-10b", name),
&data[..10],
|b, data| b.iter(|| black_box(imp(1, 0, data))),
);

g.throughput(Throughput::Bytes(10_000)).bench_with_input(
format!("{}-10k", name),
&data[..10_000],
|b, data| b.iter(|| black_box(imp(1, 0, data))),
);

g.throughput(Throughput::Bytes(100_000)).bench_with_input(
format!("{}-100k", name),
&data[..100_000],
|b, data| b.iter(|| black_box(imp(1, 0, data))),
);
}

criterion_group!(benches, bench);
criterion_main!(benches);

0 comments on commit f7ab310

Please sign in to comment.