Skip to content

Commit ac02ac2

Browse files
authored
Add: Benchmarking suite
2 parents 89972b2 + a95f2c0 commit ac02ac2

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ rand = "0.8.5"
1717
[dev-dependencies]
1818
pqc_core = {version = "0.1.0", features = ["load"]}
1919

20+
[target.'cfg(bench)'.dev-dependencies.criterion]
21+
criterion = "0.4.0"
22+
23+
[[bench]]
24+
name = "api"
25+
harness = false
26+
2027
[features]
2128
# By default this library uses mode3, also called Dilithium3
2229
mode2 = []

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ By default this library uses Dilithium3
8888

8989
## Testing
9090

91-
To run the known answer tests, you'll need to enable the `dilithium_kat` config flag eg.
91+
To run the known answer tests, you'll need to enable the `dilithium_kat` in `RUSTFLAGS` eg.
9292

9393
```shell
9494
RUSTFLAGS="--cfg dilithium_kat" cargo test
@@ -98,6 +98,17 @@ To run through all possible features use the [`test_matrix.sh`](./tests/test_mat
9898

9999
---
100100

101+
# Benchmarking
102+
103+
This library uses the criterion benchmarking suite. To use you must enable
104+
`bench` eg.
105+
106+
```shell
107+
RUSTFLAGS="--cfg bench" cargo bench
108+
```
109+
110+
---
111+
101112
## Alternatives
102113

103114
The PQClean project has rust bindings for their C post quantum libraries.

benches/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Benchmarking
2+
3+
This library uses the criterion benchmarking suite. To use you must enable
4+
`bench` in `RUSTFLAGS` eg.
5+
6+
```shell
7+
RUSTFLAGS="--cfg bench" cargo bench
8+
```

benches/api.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use pqc_dilithium::*;
3+
4+
fn sign_small_msg(c: &mut Criterion)
5+
{
6+
let keys = Keypair::generate();
7+
let msg = "Hello".as_bytes();
8+
c.bench_function("Sign Small Message", |b| {
9+
b.iter(|| keys.sign(black_box(msg)))
10+
});
11+
}
12+
13+
fn verify_small_msg(c: &mut Criterion)
14+
{
15+
let keys = Keypair::generate();
16+
let msg = "Hello".as_bytes();
17+
let sig = keys.sign(msg);
18+
c.bench_function("Verify Small Message", |b| {
19+
b.iter(|| verify(black_box(sig), black_box(msg), black_box(&keys.public)))
20+
});
21+
}
22+
23+
criterion_group!(benches, sign_small_msg, verify_small_msg);
24+
criterion_main!(benches);

0 commit comments

Comments
 (0)