-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,4 @@ criterion = "0.3" # 0.5.1 latest | |
|
||
[[bench]] | ||
name = "my_benchmark" | ||
harness = false | ||
harness = false |
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 |
---|---|---|
@@ -1,9 +1,79 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use enc_rust::fibonacci; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use enc_rust::kem::*; | ||
|
||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20)))); | ||
pub fn gen_key_benchmark_512(c: &mut Criterion) { | ||
c.bench_function("key_gen_bench_512", |b| { | ||
b.iter(|| generate_key_pair(None, 2)) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); | ||
pub fn gen_key_benchmark_768(c: &mut Criterion) { | ||
c.bench_function("key_gen_bench_768", |b| { | ||
b.iter(|| generate_key_pair(None, 3)) | ||
}); | ||
} | ||
|
||
pub fn gen_key_benchmark_1024(c: &mut Criterion) { | ||
c.bench_function("key_gen_bench_1024", |b| { | ||
b.iter(|| generate_key_pair(None, 4)) | ||
}); | ||
} | ||
|
||
pub fn encap_benchmark_512(c: &mut Criterion) { | ||
let (pk, _) = generate_key_pair(None, 2).unwrap(); | ||
c.bench_function("encap_benchmark_512", |b| { | ||
b.iter(|| pk.encapsulate(None, None)) | ||
}); | ||
} | ||
|
||
pub fn encap_benchmark_768(c: &mut Criterion) { | ||
let (pk, _) = generate_key_pair(None, 3).unwrap(); | ||
c.bench_function("encap_benchmark_768", |b| { | ||
b.iter(|| pk.encapsulate(None, None)) | ||
}); | ||
} | ||
|
||
pub fn encap_benchmark_1024(c: &mut Criterion) { | ||
let (pk, _) = generate_key_pair(None, 4).unwrap(); | ||
c.bench_function("encap_benchmark_1024", |b| { | ||
b.iter(|| pk.encapsulate(None, None)) | ||
}); | ||
} | ||
|
||
pub fn decap_benchmark_512(c: &mut Criterion) { | ||
let (pk, sk) = generate_key_pair(None, 2).unwrap(); | ||
let (ciphertext_obj, _) = pk.encapsulate(None, None).unwrap(); | ||
c.bench_function("decap_benchmark_512", |b| { | ||
b.iter(|| sk.decapsulate(ciphertext_obj.as_bytes())) | ||
}); | ||
} | ||
|
||
pub fn decap_benchmark_768(c: &mut Criterion) { | ||
let (pk, sk) = generate_key_pair(None, 3).unwrap(); | ||
let (ciphertext_obj, _) = pk.encapsulate(None, None).unwrap(); | ||
c.bench_function("decap_benchmark_768", |b| { | ||
b.iter(|| sk.decapsulate(ciphertext_obj.as_bytes())) | ||
}); | ||
} | ||
|
||
pub fn decap_benchmark_1024(c: &mut Criterion) { | ||
let (pk, sk) = generate_key_pair(None, 4).unwrap(); | ||
let (ciphertext_obj, _) = pk.encapsulate(None, None).unwrap(); | ||
c.bench_function("decap_benchmark_1024", |b| { | ||
b.iter(|| sk.decapsulate(ciphertext_obj.as_bytes())) | ||
}); | ||
} | ||
|
||
criterion_group!( | ||
benches, | ||
gen_key_benchmark_512, | ||
gen_key_benchmark_768, | ||
gen_key_benchmark_1024, | ||
encap_benchmark_512, | ||
encap_benchmark_768, | ||
encap_benchmark_1024, | ||
decap_benchmark_512, | ||
decap_benchmark_768, | ||
decap_benchmark_1024 | ||
); | ||
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