Skip to content

Commit

Permalink
Add benches for rest of predefined schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
quackzar committed Oct 1, 2024
1 parent 1b5c6b3 commit 9b815d5
Show file tree
Hide file tree
Showing 6 changed files with 386 additions and 9 deletions.
14 changes: 14 additions & 0 deletions wecare/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,17 @@ harness = false
[[bench]]
name = "shamir-25519"
harness = false

[[bench]]
name = "feldman-25519"
harness = false

[[bench]]
name = "spdz-32"
harness = false

[[bench]]
name = "shamir-32"
harness = false


114 changes: 114 additions & 0 deletions wecare/benches/feldman-25519.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
use criterion::{criterion_group, criterion_main, Criterion};
use std::{hint::black_box, thread};
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) {
let clock = std::time::Instant::now();
print!("Setting up engines...");
let _ = std::io::stdout().flush();
let (e1, e2) = thread::scope(|scope| {
let e2 = scope.spawn(|| {
Engine::builder()
.address("127.0.0.1:1234")
.participant("127.0.0.1:1235")
.scheme(SchemeKind::Feldman)
.field(FieldKind::Curve25519)
.single_threaded_runtime()
.connect_blocking()
.unwrap()
.build()
.unwrap()
});
let e1 = scope.spawn(|| {
thread::sleep(Duration::from_millis(200));
Engine::builder()
.address("127.0.0.1:1235")
.participant("127.0.0.1:1234")
.scheme(SchemeKind::Feldman)
.field(FieldKind::Curve25519)
.single_threaded_runtime()
.connect_blocking()
.unwrap()
.build()
.unwrap()
});
(e1.join().unwrap(), e2.join().unwrap())
});
println!(" Complete! (took {:#?})", clock.elapsed());
(e1, e2)
}

fn criterion_benchmark(c: &mut Criterion) {
let (mut e1, mut e2) = build_feldman_engines();
c.bench_function("feldman-25519 single", |b| {
let input1 = vec![7.0];
let input2 = vec![3.0];
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();
});
});
});
c.bench_function("feldman-25519 vec32", |b| {
let input1 = vec![7.0; 32];
let input2 = vec![3.0; 32];
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();
});
});
});
c.bench_function("feldman-25519 vec64", |b| {
let input1 = vec![7.0; 64];
let input2 = vec![3.0; 64];
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();
});
});
});
c.bench_function("feldman-25519 vec128", |b| {
let input1 = vec![7.0; 128];
let input2 = vec![3.0; 128];
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();
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
8 changes: 4 additions & 4 deletions wecare/benches/shamir-25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn build_shamir_engines() -> (blocking::Engine, blocking::Engine) {

fn criterion_benchmark(c: &mut Criterion) {
let (mut e1, mut e2) = build_shamir_engines();
c.bench_function("shamir single", |b| {
c.bench_function("shamir-25519 single", |b| {
let input1 = vec![7.0];
let input2 = vec![3.0];
b.iter(|| {
Expand All @@ -58,7 +58,7 @@ fn criterion_benchmark(c: &mut Criterion) {
});
});
});
c.bench_function("shamir vec32", |b| {
c.bench_function("shamir-25519 vec32", |b| {
let input1 = vec![7.0; 32];
let input2 = vec![3.0; 32];
b.iter(|| {
Expand All @@ -74,7 +74,7 @@ fn criterion_benchmark(c: &mut Criterion) {
});
});
});
c.bench_function("shamir vec64", |b| {
c.bench_function("shamir-25519 vec64", |b| {
let input1 = vec![7.0; 64];
let input2 = vec![3.0; 64];
b.iter(|| {
Expand All @@ -90,7 +90,7 @@ fn criterion_benchmark(c: &mut Criterion) {
});
});
});
c.bench_function("shamir vec128", |b| {
c.bench_function("shamir-25519 vec128", |b| {
let input1 = vec![7.0; 128];
let input2 = vec![3.0; 128];
b.iter(|| {
Expand Down
114 changes: 114 additions & 0 deletions wecare/benches/shamir-32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
use criterion::{criterion_group, criterion_main, Criterion};
use std::{hint::black_box, thread};
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) {
let clock = std::time::Instant::now();
print!("Setting up engines...");
let _ = std::io::stdout().flush();
let (e1, e2) = thread::scope(|scope| {
let e2 = scope.spawn(|| {
Engine::builder()
.address("127.0.0.1:1234")
.participant("127.0.0.1:1235")
.scheme(SchemeKind::Shamir)
.field(FieldKind::Element32)
.single_threaded_runtime()
.connect_blocking()
.unwrap()
.build()
.unwrap()
});
let e1 = scope.spawn(|| {
thread::sleep(Duration::from_millis(200));
Engine::builder()
.address("127.0.0.1:1235")
.participant("127.0.0.1:1234")
.scheme(SchemeKind::Shamir)
.field(FieldKind::Element32)
.single_threaded_runtime()
.connect_blocking()
.unwrap()
.build()
.unwrap()
});
(e1.join().unwrap(), e2.join().unwrap())
});
println!(" Complete! (took {:#?})", clock.elapsed());
(e1, e2)
}

fn criterion_benchmark(c: &mut Criterion) {
let (mut e1, mut e2) = build_shamir_engines();
c.bench_function("shamir-32 single", |b| {
let input1 = vec![7.0];
let input2 = vec![3.0];
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();
});
});
});
c.bench_function("shamir-32 vec32", |b| {
let input1 = vec![7.0; 32];
let input2 = vec![3.0; 32];
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();
});
});
});
c.bench_function("shamir-32 vec64", |b| {
let input1 = vec![7.0; 64];
let input2 = vec![3.0; 64];
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();
});
});
});
c.bench_function("shamir-32 vec128", |b| {
let input1 = vec![7.0; 128];
let input2 = vec![3.0; 128];
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();
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
10 changes: 5 additions & 5 deletions wecare/benches/spdz-25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn precompute(n: usize) -> (File, File) {
}

fn build_spdz_engines() -> (blocking::Engine, blocking::Engine) {
let (ctx1, ctx2) = precompute(10000000);
let (ctx1, mut ctx2) = precompute(10000000);
let clock = time::Instant::now();
print!("Setting up engines...");
let _ = std::io::stdout().flush();
Expand Down Expand Up @@ -63,7 +63,7 @@ fn build_spdz_engines() -> (blocking::Engine, blocking::Engine) {

fn criterion_benchmark(c: &mut Criterion) {
let (mut e1, mut e2) = build_spdz_engines();
c.bench_function("spdz single", |b| {
c.bench_function("spdz-25519 single", |b| {
let input1 = vec![7.0];
let input2 = vec![3.0];
b.iter(|| {
Expand All @@ -79,7 +79,7 @@ fn criterion_benchmark(c: &mut Criterion) {
});
});
});
c.bench_function("spdz vec32", |b| {
c.bench_function("spdz-25519 vec32", |b| {
let input1 = vec![7.0; 32];
let input2 = vec![3.0; 32];
b.iter(|| {
Expand All @@ -95,7 +95,7 @@ fn criterion_benchmark(c: &mut Criterion) {
});
});
});
c.bench_function("spdz vec64", |b| {
c.bench_function("spdz-25519 vec64", |b| {
let input1 = vec![7.0; 64];
let input2 = vec![3.0; 64];
b.iter(|| {
Expand All @@ -111,7 +111,7 @@ fn criterion_benchmark(c: &mut Criterion) {
});
});
});
c.bench_function("spdz vec128", |b| {
c.bench_function("spdz-25519 vec128", |b| {
let input1 = vec![7.0; 128];
let input2 = vec![3.0; 128];
b.iter(|| {
Expand Down
Loading

0 comments on commit 9b815d5

Please sign in to comment.