Skip to content

Commit

Permalink
Use criterion for benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
wackywendell committed Mar 7, 2020
1 parent 9167a8b commit 7fead5f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
17 changes: 15 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,21 @@ A package for calculating primes using the Sieve of Eratosthenes, and using that
number is prime and calculating factors. Includes an iterator over all primes.
"""

readme="README.md"
readme = "README.md"

documentation = "https://wackywendell.github.io/primes/"
homepage = "https://github.com/wackywendell/primes/tree/master"
repository = "https://github.com/wackywendell/primes/tree/master"
repository = "https://github.com/wackywendell/primes/tree/master"

[lib]
# Disable benches in the normal library, we don't need them
# Without disabling this, running cargo bench -- --something-else gets somehow passed to both
# the cargo bench binary and the compiled benches binary
bench = false

[dev-dependencies]
criterion = "0.3.1"

[[bench]]
name = "benches"
harness = false
32 changes: 20 additions & 12 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
#![feature(test)]

extern crate test;
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};

use primes::PrimeSet;
use test::Bencher;

#[bench]
fn bench_primes(b: &mut Bencher) {
b.iter(|| {
let mut pset = PrimeSet::new();
let (_, _) = pset.find(1_000_000);
//~ let (idx, n) = pset.find(1_000_000);
//~ println!("Prime {}: {}", idx, n);
})
fn bench_primes(c: &mut Criterion) {
let mut group = c.benchmark_group("PrimeSet::find");
for size in [
100, 200, 500, 1_000, 2_000, 5_000, 10_000, 20_000, 50_000, 100_000, 200_000, 500_000,
]
.iter()
{
group.throughput(Throughput::Elements(*size as u64));
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
b.iter(|| {
let mut pset = PrimeSet::new();
black_box(pset.find(size))
})
});
}
group.finish();
}

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

0 comments on commit 7fead5f

Please sign in to comment.