Skip to content

Commit

Permalink
Fix BenchmarkGroup::bench_function() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Nov 6, 2023
1 parent c239f3c commit c26f104
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
51 changes: 29 additions & 22 deletions crates/subspace-core-primitives/benches/kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,48 @@ fn criterion_benchmark(c: &mut Criterion) {
})
});

c.bench_function("commit", |b| {
{
let polynomial = kzg.poly(&values).unwrap();
b.iter(|| {
kzg.commit(black_box(&polynomial)).unwrap();
})
});

c.bench_function("commit", |b| {
b.iter(|| {
kzg.commit(black_box(&polynomial)).unwrap();
})
});
}

let num_values = values.len();

c.bench_function("create-witness", |b| {
{
let polynomial = kzg.poly(&values).unwrap();

b.iter(|| {
kzg.create_witness(black_box(&polynomial), black_box(num_values), black_box(0))
.unwrap();
})
});
c.bench_function("create-witness", |b| {
b.iter(|| {
kzg.create_witness(black_box(&polynomial), black_box(num_values), black_box(0))
.unwrap();
})
});
}

c.bench_function("verify", |b| {
{
let polynomial = kzg.poly(&values).unwrap();
let commitment = kzg.commit(&polynomial).unwrap();
let index = 0;
let witness = kzg.create_witness(&polynomial, num_values, index).unwrap();
let value = values.first().unwrap();

b.iter(|| {
kzg.verify(
black_box(&commitment),
black_box(num_values),
black_box(index),
black_box(value),
black_box(&witness),
);
})
});
c.bench_function("verify", |b| {
b.iter(|| {
kzg.verify(
black_box(&commitment),
black_box(num_values),
black_box(index),
black_box(value),
black_box(&witness),
);
})
});
}
}

criterion_group!(benches, criterion_benchmark);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ fn criterion_benchmark(c: &mut Criterion) {

let cpu_cores = core_affinity::get_core_ids().expect("Must be able to get CPU cores");
for cpu_core in cpu_cores {
if !core_affinity::set_for_current(cpu_core) {
panic!("Failed to set CPU affinity");
}

c.bench_function(&format!("prove/cpu-{}", cpu_core.id), move |b| {
if !core_affinity::set_for_current(cpu_core) {
panic!("Failed to set CPU affinity");
}
b.iter(|| {
black_box(prove(black_box(seed), black_box(pot_iterations))).unwrap();
})
Expand Down

0 comments on commit c26f104

Please sign in to comment.