mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-07 20:50:39 +00:00
Add criterion benchmark for diffie_hellman() function.
This commit is contained in:
parent
031179d111
commit
659d6c258e
3 changed files with 54 additions and 2 deletions
|
|
@ -5,7 +5,7 @@ rust:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- TEST_COMMAND=test EXTRA_FLAGS='' FEATURES=''
|
- TEST_COMMAND=test EXTRA_FLAGS='' FEATURES=''
|
||||||
- TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='bench'
|
- TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES=''
|
||||||
- TEST_COMMAND=build EXTRA_FLAGS='--no-default-features' FEATURES='nightly'
|
- TEST_COMMAND=build EXTRA_FLAGS='--no-default-features' FEATURES='nightly'
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,14 @@ version = "^0.12"
|
||||||
optional = true
|
optional = true
|
||||||
version = "^0.3"
|
version = "^0.3"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
criterion = "0.2"
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "x25519"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
bench = []
|
|
||||||
default = ["std", "nightly"]
|
default = ["std", "nightly"]
|
||||||
std = ["rand", "curve25519-dalek/std"]
|
std = ["rand", "curve25519-dalek/std"]
|
||||||
nightly = ["curve25519-dalek/nightly"]
|
nightly = ["curve25519-dalek/nightly"]
|
||||||
|
|
|
||||||
46
benches/x25519.rs
Normal file
46
benches/x25519.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
// -*- mode: rust; -*-
|
||||||
|
//
|
||||||
|
// This file is part of x25519-dalek.
|
||||||
|
// Copyright (c) 2017 Isis Lovecruft
|
||||||
|
// See LICENSE for licensing information.
|
||||||
|
//
|
||||||
|
// Authors:
|
||||||
|
// - Isis Agora Lovecruft <isis@patternsinthevoid.net>
|
||||||
|
|
||||||
|
//! Benchmark the Diffie-Hellman operation.
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate criterion;
|
||||||
|
extern crate rand;
|
||||||
|
extern crate x25519_dalek;
|
||||||
|
|
||||||
|
use criterion::Criterion;
|
||||||
|
|
||||||
|
use rand::OsRng;
|
||||||
|
|
||||||
|
use x25519_dalek::generate_public;
|
||||||
|
use x25519_dalek::generate_secret;
|
||||||
|
use x25519_dalek::diffie_hellman;
|
||||||
|
|
||||||
|
fn bench_diffie_hellman(c: &mut Criterion) {
|
||||||
|
let mut csprng: OsRng = OsRng::new().unwrap();
|
||||||
|
let alice_secret: [u8; 32] = generate_secret(&mut csprng);
|
||||||
|
let bob_secret: [u8; 32] = generate_secret(&mut csprng);
|
||||||
|
let bob_public: [u8; 32] = generate_public(&bob_secret).to_bytes();
|
||||||
|
|
||||||
|
c.bench_function("diffie_hellman", move |b| {
|
||||||
|
b.iter(||
|
||||||
|
diffie_hellman(&alice_secret, &bob_public)
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!{
|
||||||
|
name = x25519_benches;
|
||||||
|
config = Criterion::default();
|
||||||
|
targets =
|
||||||
|
bench_diffie_hellman,
|
||||||
|
}
|
||||||
|
criterion_main!{
|
||||||
|
x25519_benches,
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue