-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benches for rest of predefined schemes
- Loading branch information
Showing
6 changed files
with
386 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.