Skip to content

Commit

Permalink
Use parameterized inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
quackzar committed Oct 1, 2024
1 parent 9b815d5 commit 7fe444b
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 315 deletions.
82 changes: 19 additions & 63 deletions wecare/benches/feldman-25519.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use std::{hint::black_box, thread};
use std::{io::Write, time::Duration};
use wecare::vm::{blocking, FieldKind};
Expand Down Expand Up @@ -42,70 +42,26 @@ fn build_feldman_engines() -> (blocking::Engine, blocking::Engine) {

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 mut group = c.benchmark_group("feldman-25519");
for n in [1, 8, 16, 32, 64, 128] {
group.bench_function(BenchmarkId::from_parameter(n), |b| {
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 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();
}
Expand Down
82 changes: 19 additions & 63 deletions wecare/benches/shamir-25519.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use std::{hint::black_box, thread};
use std::{io::Write, time::Duration};
use wecare::vm::{blocking, FieldKind};
Expand Down Expand Up @@ -42,70 +42,26 @@ 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-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 mut group = c.benchmark_group("shamir-25519");
for n in [1, 8, 16, 32, 64, 128] {
group.bench_function(BenchmarkId::from_parameter(n), |b| {
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 t2 = scope.spawn(|| {
black_box(e2.sum(&input2));
});
t1.join().unwrap();
t2.join().unwrap();
});
});
});
c.bench_function("shamir-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("shamir-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("shamir-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();
}
Expand Down
82 changes: 19 additions & 63 deletions wecare/benches/shamir-32.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use std::{hint::black_box, thread};
use std::{io::Write, time::Duration};
use wecare::vm::{blocking, FieldKind};
Expand Down Expand Up @@ -42,70 +42,26 @@ 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-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 mut group = c.benchmark_group("shamir-32");
for n in [1, 8, 16, 32, 64, 128] {
group.bench_function(BenchmarkId::from_parameter(n), |b| {
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 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();
}
Expand Down
82 changes: 19 additions & 63 deletions wecare/benches/spdz-25519.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use std::time;
use std::{fs::File, hint::black_box, io::Seek, thread};
use std::{io::Write, time::Duration};
Expand Down Expand Up @@ -63,70 +63,26 @@ 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-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 mut group = c.benchmark_group("spdz-25519");
for n in [1, 8, 16, 32, 64, 128] {
group.bench_function(BenchmarkId::from_parameter(n), |b| {
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 t2 = scope.spawn(|| {
black_box(e2.sum(&input2));
});
t1.join().unwrap();
t2.join().unwrap();
});
});
});
c.bench_function("spdz-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("spdz-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("spdz-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();
}
Expand Down
Loading

0 comments on commit 7fe444b

Please sign in to comment.