Skip to content

Commit

Permalink
Move setup into iter
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Jul 30, 2024
1 parent 850d2c4 commit 06587e0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions crates/chia-bls/benches/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,45 @@ fn cache_benchmark(c: &mut Criterion) {
pks.push(pk);
}

let bls_cache = BlsCache::default();
c.bench_function("bls_cache.aggregate_verify, 0% cache hits", |b| {
b.iter(|| {
let bls_cache = BlsCache::default();
assert!(bls_cache.aggregate_verify(pks.iter().zip([&msg].iter().cycle()), &agg_sig));
});
});

// populate 10% of keys
let bls_cache = BlsCache::default();
bls_cache.aggregate_verify(pks[0..100].iter().zip([&msg].iter().cycle()), &agg_sig);
c.bench_function("bls_cache.aggregate_verify, 10% cache hits", |b| {
b.iter(|| {
let bls_cache = BlsCache::default();
bls_cache.aggregate_verify(pks[0..100].iter().zip([&msg].iter().cycle()), &agg_sig);
assert!(bls_cache.aggregate_verify(pks.iter().zip([&msg].iter().cycle()), &agg_sig));
});
});

// populate another 10% of keys
let bls_cache = BlsCache::default();
bls_cache.aggregate_verify(pks[0..200].iter().zip([&msg].iter().cycle()), &agg_sig);
c.bench_function("bls_cache.aggregate_verify, 20% cache hits", |b| {
b.iter(|| {
let bls_cache = BlsCache::default();
bls_cache.aggregate_verify(pks[0..200].iter().zip([&msg].iter().cycle()), &agg_sig);
assert!(bls_cache.aggregate_verify(pks.iter().zip([&msg].iter().cycle()), &agg_sig));
});
});

// populate another 30% of keys
let bls_cache = BlsCache::default();
bls_cache.aggregate_verify(pks[0..500].iter().zip([&msg].iter().cycle()), &agg_sig);
c.bench_function("bls_cache.aggregate_verify, 50% cache hits", |b| {
b.iter(|| {
let bls_cache = BlsCache::default();
bls_cache.aggregate_verify(pks[0..500].iter().zip([&msg].iter().cycle()), &agg_sig);
assert!(bls_cache.aggregate_verify(pks.iter().zip([&msg].iter().cycle()), &agg_sig));
});
});

// populate all other keys
let bls_cache = BlsCache::default();
bls_cache.aggregate_verify(pks[0..1000].iter().zip([&msg].iter().cycle()), &agg_sig);
c.bench_function("bls_cache.aggregate_verify, 100% cache hits", |b| {
b.iter(|| {
let bls_cache = BlsCache::default();
bls_cache.aggregate_verify(pks[0..1000].iter().zip([&msg].iter().cycle()), &agg_sig);
assert!(bls_cache.aggregate_verify(pks.iter().zip([&msg].iter().cycle()), &agg_sig));
});
});
Expand Down

0 comments on commit 06587e0

Please sign in to comment.