Skip to content

Commit

Permalink
Add benches
Browse files Browse the repository at this point in the history
  • Loading branch information
tanyav2 committed Dec 14, 2020
1 parent c970eaf commit 7efe374
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Run benches
run: cargo bench
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ serde = { version = "1.0", features = [ "derive" ] }
serde_repr = "0.1"

[dev-dependencies]
criterion = "0.3"
hex = "0.4"
serde_json = "1.0"
tokio = { version = "0.2", features = [ "full" ] }

[[bench]]
name = "odoh_bench"
harness = false
61 changes: 61 additions & 0 deletions benches/odoh_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use hpke::Serializable;
use odoh_rs::key_utils::*;
use odoh_rs::protocol::*;

fn generate_key_pair() -> ObliviousDoHKeyPair {
let ikm = "871389a8727130974e3eb3ee528d440a871389a8727130974e3eb3ee528d440a";
let ikm_bytes = hex::decode(ikm).unwrap();
let (secret_key, public_key) = derive_keypair_from_seed(&ikm_bytes);
let public_key_bytes = public_key.to_bytes().to_vec();
let odoh_public_key = ObliviousDoHConfigContents {
kem_id: 0x0020,
kdf_id: 0x0001,
aead_id: 0x0001,
public_key: public_key_bytes,
};
ObliviousDoHKeyPair {
private_key: secret_key,
public_key: odoh_public_key,
}
}

fn generate_query_body() -> ObliviousDoHQueryBody {
ObliviousDoHQueryBody::new(
&hex::decode("5513010000010000000000000377777706676f6f676c6503636f6d00001c0001").unwrap(),
None,
)
}

pub fn bench_parse_query(c: &mut Criterion) {
let key_pair = generate_key_pair();
let query = generate_query_body();
let (oblivious_query, _) = create_query_msg(&key_pair.public_key, &query).unwrap();
c.bench_function("parse_received_query", |b| {
b.iter(|| black_box(parse_received_query(&key_pair, &oblivious_query)))
});
}

pub fn bench_parse_response(c: &mut Criterion) {
let client_secret = vec![
185, 1, 153, 19, 244, 146, 251, 107, 66, 227, 209, 137, 191, 128, 219, 44, 12, 154, 195,
137, 220, 77, 86, 149, 207, 128, 202, 85, 85, 182, 171, 215,
];
let generated_resp = vec![
2, 0, 0, 0, 26, 165, 223, 11, 24, 56, 158, 31, 166, 11, 144, 56, 129, 76, 247, 176, 49,
168, 168, 106, 68, 188, 192, 104, 89, 213, 9,
];
let query = generate_query_body();
c.bench_function("parse_received_response", |b| {
b.iter(|| {
black_box(parse_received_response(
&client_secret,
&generated_resp,
&query,
))
})
});
}

criterion_group!(benches, bench_parse_query, bench_parse_response);
criterion_main!(benches);

0 comments on commit 7efe374

Please sign in to comment.