Skip to content

Commit

Permalink
add fix_var benches
Browse files Browse the repository at this point in the history
  • Loading branch information
kunxian-xia committed Jul 2, 2024
1 parent e5e160a commit 86573f3
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions multilinear_extensions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ goldilocks.workspace = true
rayon.workspace = true
serde.workspace = true

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }

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

[features]
parallel = [ ]
70 changes: 70 additions & 0 deletions multilinear_extensions/benches/mle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use ark_std::rand::thread_rng;
use criterion::*;
use ff::Field;
use goldilocks::GoldilocksExt2;
use multilinear_extensions::mle::DenseMultilinearExtension;

fn fix_var(c: &mut Criterion) {
let mut rng = thread_rng();

const NUM_SAMPLES: usize = 10;
for nv in 12..20 {
let mut group = c.benchmark_group("mle");
group.sample_size(NUM_SAMPLES);

for i in 0..nv {
group.bench_function(
BenchmarkId::new("fix_var", format!("({},{})", nv, nv - i)),
|b| {
b.iter_with_setup(
|| {
let mut v =
DenseMultilinearExtension::<GoldilocksExt2>::random(nv, &mut rng);
let r = GoldilocksExt2::random(&mut rng);
for _ in 0..i {
v.fix_variables_in_place(&[r]);
}
(v, r)
},
|(mut v, r)| v.fix_variables_in_place(&[r]),
);
},
);
}
group.finish();
}
}

fn fix_var_par(c: &mut Criterion) {
let mut rng = thread_rng();

const NUM_SAMPLES: usize = 10;
for nv in 12..20 {
let mut group = c.benchmark_group("mle");
group.sample_size(NUM_SAMPLES);

for i in 0..nv {
group.bench_function(
BenchmarkId::new("fix_var_par", format!("({},{})", nv, nv - i)),
|b| {
b.iter_with_setup(
|| {
let mut v =
DenseMultilinearExtension::<GoldilocksExt2>::random(nv, &mut rng);
let r = GoldilocksExt2::random(&mut rng);
for _ in 0..i {
v.fix_variables_in_place(&[r]);
}
(v, r)
},
|(mut v, r)| v.fix_variables_in_place_parallel(&[r]),
);
},
);
}
group.finish();
}
}

criterion_group!(benches, fix_var, fix_var_par,);
criterion_main!(benches);

0 comments on commit 86573f3

Please sign in to comment.