diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2021-01-15 16:54:09 +0100 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2021-01-15 17:55:29 +0100 |
commit | 5d484b5c36dd175c4d8289c280898be094599cdb (patch) | |
tree | a59207262890e9be3d1650c2286a449fd8e6f5c0 | |
parent | 0458bcfa6f0a5b6a379de6b9eba1ad2c07c7329f (diff) |
openpgp: rename benchmark, read manually
-rw-r--r-- | openpgp/Cargo.toml | 2 | ||||
-rw-r--r-- | openpgp/benches/random.rs | 58 | ||||
-rw-r--r-- | openpgp/benches/read_keys.rs | 36 | ||||
-rw-r--r-- | openpgp/src/lib.rs | 3 |
4 files changed, 38 insertions, 61 deletions
diff --git a/openpgp/Cargo.toml b/openpgp/Cargo.toml index a32dbac4..d8186c8e 100644 --- a/openpgp/Cargo.toml +++ b/openpgp/Cargo.toml @@ -83,5 +83,5 @@ name = "pad" required-features = ["compression-deflate"] [[bench]] -name = "random" +name = "read_keys" harness = false diff --git a/openpgp/benches/random.rs b/openpgp/benches/random.rs deleted file mode 100644 index 2d64eee3..00000000 --- a/openpgp/benches/random.rs +++ /dev/null @@ -1,58 +0,0 @@ -use criterion::{black_box, Throughput, criterion_group, criterion_main, Criterion}; - -use sequoia_openpgp::crypto; -use sequoia_openpgp::cert::Cert; - -use sequoia_openpgp::parse::Parse; - -fn run_random(size: usize) { - let mut buf = vec![0; size]; - crypto::random(&mut buf); -} - -fn read_lutz_key() { - let _lutz = Cert::from_bytes(sequoia_openpgp::tests::key("lutz.gpg")).unwrap(); -} - -fn read_key(bytes: &[u8]) { - - // copied from cert.rs::test_into_packets - // Tests that Cert::into_packets() and Cert::serialize(..) agree. - let _dkg = Cert::from_bytes(bytes); - - //let mut buf = Vec::new(); - //for p in dkg.clone().into_packets() { - // p.serialize(&mut buf)?; - //} - //let dkg = dkg.to_vec()?; - //if false && buf != dkg { - // std::fs::write("/tmp/buf", &buf)?; - // std::fs::write("/tmp/dkg", &dkg)?; - //} - //assert_eq!(buf, dkg); - //Ok(()) -} - -fn bench_random(c: &mut Criterion) { - let mut group = c.benchmark_group("bench_crypto_random"); - - group.sample_size(50); - for i in (8..33).step_by(8) { - group.throughput(Throughput::Bytes(i as u64)); - group.bench_function(format!("crypto::random {:02}", i), |b| b.iter(|| run_random(black_box(i)) )); - }; - group.finish(); -} - -fn bench_read_keys(c: &mut Criterion) { - let mut group = c.benchmark_group("read keys"); - let foo = ["dkg.gpg", "lutz.gpg"]; - foo.iter().for_each(|&filename| { - let bytes = sequoia_openpgp::tests::key(filename); - group.bench_function(filename, |b| b.iter(|| read_key(bytes))); - }); - group.finish(); -} - -criterion_group!(benches, bench_read_keys); -criterion_main!(benches); diff --git a/openpgp/benches/read_keys.rs b/openpgp/benches/read_keys.rs new file mode 100644 index 00000000..34f1a045 --- /dev/null +++ b/openpgp/benches/read_keys.rs @@ -0,0 +1,36 @@ +use criterion::{criterion_group, criterion_main, Criterion}; + +use sequoia_openpgp::cert::Cert; +use sequoia_openpgp::parse::Parse; + +fn read_key(bytes: &[u8]) { + let _ = Cert::from_bytes(bytes); +} + +//fn bench_random(c: &mut Criterion) { +// let mut group = c.benchmark_group("bench_crypto_random"); +// +// group.sample_size(50); +// for i in (8..33).step_by(8) { +// group.throughput(Throughput::Bytes(i as u64)); +// group.bench_function(format!("crypto::random {:02}", i), |b| b.iter(|| run_random(black_box(i)) )); +// }; +// group.finish(); +//} + +macro_rules! bench_parse_key { + ( $filename: expr, $group: expr ) => { + let bytes = include_bytes!(concat!("../tests/data/keys/", $filename)); + $group.bench_function($filename, |b| b.iter(|| read_key(bytes))); + } + +} +fn bench_read_keys(c: &mut Criterion) { + let mut group = c.benchmark_group("read keys"); + bench_parse_key!("dkg.gpg", group); + bench_parse_key!("lutz.gpg", group); + group.finish(); +} + +criterion_group!(benches, bench_read_keys); +criterion_main!(benches); diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index dce0ded3..b86b986d 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -165,8 +165,7 @@ pub mod policy; pub(crate) mod seal; pub(crate) mod utils; -//#[cfg(test)] -//#[cfg(any(bench, test))] +#[cfg(test)] pub mod tests; /// Returns a timestamp for the tests. |