Skip to content

Commit

Permalink
Add group bench
Browse files Browse the repository at this point in the history
  • Loading branch information
quackzar committed Oct 1, 2024
1 parent 7fe444b commit a7b2426
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 5 deletions.
4 changes: 4 additions & 0 deletions wecare/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ tokio-test = "0.4.4"
criterion = "0.5.1"
tempfile = "3.10.1"

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

[[bench]]
name = "spdz-25519"
harness = false
Expand Down
60 changes: 60 additions & 0 deletions wecare/benches/all.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use criterion::{criterion_group, criterion_main, measurement::Measurement, BenchmarkGroup, BenchmarkId, Criterion};
use wecare::vm::blocking::Engine;
use std::{hint::black_box, thread};


mod spdz25519 {
include!("./spdz-25519.rs");
}
mod spdz32 {
include!("./spdz-32.rs");
}
mod shamir25519 {
include!("./shamir-25519.rs");
}
mod shamir32 {
include!("./shamir-32.rs");
}
mod feldman25519 {
include!("./feldman-25519.rs");
}


fn bench<M: Measurement>(g: &mut BenchmarkGroup<'_, M>, label: &'static str, engines: impl Fn() -> (Engine, Engine)) {
let (mut e1, mut e2) = engines();
for size in [1, 8, 16, 32, 64] {
g.bench_with_input(BenchmarkId::new(label, size), &size, |b, n| {
let input1 = vec![7.0; *n];
let input2 = vec![3.0; *n];
b.iter(|| {
thread::scope(|scope| {
let t1 = scope.spawn(|| {
black_box(e1.sum(&input1));
});
let t2 = scope.spawn(|| {
black_box(e2.sum(&input2));
});
t1.join().unwrap();
t2.join().unwrap();
});
})
});
}

let _ = e1.shutdown();
let _ = e2.shutdown();
}


fn criterion_benchmark(c: &mut Criterion) {
let mut g = c.benchmark_group("sum-2");
bench(&mut g, "spdz-25519", spdz25519::build_spdz_engines);
bench(&mut g, "spdz-32", spdz32::build_spdz_engines);
bench(&mut g, "shamir-25519", shamir25519::build_shamir_engines);
bench(&mut g, "shamir-32", shamir32::build_shamir_engines);
bench(&mut g, "feldman-25519", feldman25519::build_feldman_engines);
}


criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
2 changes: 1 addition & 1 deletion wecare/benches/feldman-25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{io::Write, time::Duration};
use wecare::vm::{blocking, FieldKind};
use wecare::{vm::Engine, vm::SchemeKind};

fn build_feldman_engines() -> (blocking::Engine, blocking::Engine) {
pub fn build_feldman_engines() -> (blocking::Engine, blocking::Engine) {
let clock = std::time::Instant::now();
print!("Setting up engines...");
let _ = std::io::stdout().flush();
Expand Down
2 changes: 1 addition & 1 deletion wecare/benches/shamir-25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{io::Write, time::Duration};
use wecare::vm::{blocking, FieldKind};
use wecare::{vm::Engine, vm::SchemeKind};

fn build_shamir_engines() -> (blocking::Engine, blocking::Engine) {
pub fn build_shamir_engines() -> (blocking::Engine, blocking::Engine) {
let clock = std::time::Instant::now();
print!("Setting up engines...");
let _ = std::io::stdout().flush();
Expand Down
2 changes: 1 addition & 1 deletion wecare/benches/shamir-32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{io::Write, time::Duration};
use wecare::vm::{blocking, FieldKind};
use wecare::{vm::Engine, vm::SchemeKind};

fn build_shamir_engines() -> (blocking::Engine, blocking::Engine) {
pub fn build_shamir_engines() -> (blocking::Engine, blocking::Engine) {
let clock = std::time::Instant::now();
print!("Setting up engines...");
let _ = std::io::stdout().flush();
Expand Down
2 changes: 1 addition & 1 deletion wecare/benches/spdz-25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn precompute(n: usize) -> (File, File) {
(ctx1, ctx2)
}

fn build_spdz_engines() -> (blocking::Engine, blocking::Engine) {
pub fn build_spdz_engines() -> (blocking::Engine, blocking::Engine) {
let (ctx1, mut ctx2) = precompute(10000000);
let clock = time::Instant::now();
print!("Setting up engines...");
Expand Down
2 changes: 1 addition & 1 deletion wecare/benches/spdz-32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn precompute(n: usize) -> (File, File) {
(ctx1, ctx2)
}

fn build_spdz_engines() -> (blocking::Engine, blocking::Engine) {
pub fn build_spdz_engines() -> (blocking::Engine, blocking::Engine) {
let (ctx1, ctx2) = precompute(10000000);
let clock = time::Instant::now();
print!("Setting up engines...");
Expand Down

0 comments on commit a7b2426

Please sign in to comment.