From 596adff8ba56e6a13e4b35fbc5e5774fe22e28f7 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 13 Jul 2022 14:29:19 +1000 Subject: [PATCH 1/4] Remove unneeded whitespace We do not customarily put two lines of whitespace before modules. Remove unneeded whitespace from before the `benches` module. --- src/ecdsa/recovery.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ecdsa/recovery.rs b/src/ecdsa/recovery.rs index f1ade07..ce9768f 100644 --- a/src/ecdsa/recovery.rs +++ b/src/ecdsa/recovery.rs @@ -452,7 +452,6 @@ mod tests { } } - #[cfg(all(test, feature = "unstable"))] mod benches { use rand::{thread_rng, RngCore}; From ddc108c1179601f84fc832ffadfcaeab7cf5585e Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 13 Jul 2022 14:34:16 +1000 Subject: [PATCH 2/4] Increase heading size Currently the main heading of the readme uses a level three markdown heading, this is quite small. Use level two instead. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd19fb6..22f952c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [Full documentation](https://docs.rs/secp256k1/) -### rust-secp256k1 +## rust-secp256k1 `rust-secp256k1` is a wrapper around [libsecp256k1](https://github.com/bitcoin-core/secp256k1), a C library by Pieter Wuille for producing ECDSA signatures using the SECG curve From 2a1c9ab4b8908e7c83eca826c1e8523533d2d228 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 14 Jul 2022 09:33:47 +1000 Subject: [PATCH 3/4] Remove rand-std feature from unstable Currently the "unstable" feature (used to guard bench mark code) turns on the "recovery" and "rand-std" features. The "rand-std" feature is not needed since it is unused, as can be seen by the following bench runs: Before applying this patch: ... test benches::bench_sign_ecdsa ... bench: 35,454 ns/iter (+/- 1,376) test benches::bench_verify_ecdsa ... bench: 44,578 ns/iter (+/- 1,619) test benches::generate ... bench: 26,800 ns/iter (+/- 2,352) test ecdh::benches::bench_ecdh ... bench: 51,195 ns/iter (+/- 1,400) test ecdsa::recovery::benches::bench_recover ... bench: 50,174 ns/iter (+/- 1,572) test key::benches::bench_pk_ordering ... bench: 5,748 ns/iter (+/- 492) test result: ok. 0 passed; 0 failed; 76 ignored; 6 measured; 0 filtered out; finished in 14.52s After removing "rand-std" feature: ... test benches::bench_sign_ecdsa ... bench: 35,510 ns/iter (+/- 1,504) test benches::bench_verify_ecdsa ... bench: 42,483 ns/iter (+/- 5,628) test benches::generate ... bench: 26,573 ns/iter (+/- 1,333) test ecdh::benches::bench_ecdh ... bench: 50,846 ns/iter (+/- 3,982) test ecdsa::recovery::benches::bench_recover ... bench: 50,908 ns/iter (+/- 2,775) test key::benches::bench_pk_ordering ... bench: 6,002 ns/iter (+/- 463) test result: ok. 0 passed; 0 failed; 60 ignored; 6 measured; 0 filtered out; finished in 6.52s --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 03af3d3..0a41c55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ features = [ "rand", "rand-std", "serde", "bitcoin_hashes", "recovery", "global- rustdoc-args = ["--cfg", "docsrs"] [features] -unstable = ["recovery", "rand-std"] +unstable = ["recovery"] default = ["std"] std = ["alloc", "secp256k1-sys/std"] # allow use of Secp256k1::new and related API that requires an allocator From a431edb86ae60666273c21750479062dbf3a1173 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 13 Jul 2022 14:40:49 +1000 Subject: [PATCH 4/4] Create configuration conditional bench As we did in rust-bitcoin [0] create a configuration conditional `bench` that we can use to guard bench mark code. This has the benefit of making our features additive i.e., we can now test with `--all-features` with a stable toolchain (currently this fails because of our use of the `test` crate). [0] - https://github.com/rust-bitcoin/rust-bitcoin/pull/1092 --- Cargo.toml | 1 - README.md | 5 +++++ contrib/test.sh | 8 +++++--- src/ecdh.rs | 2 +- src/ecdsa/recovery.rs | 2 +- src/key.rs | 2 +- src/lib.rs | 8 +++++--- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0a41c55..0de60bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ features = [ "rand", "rand-std", "serde", "bitcoin_hashes", "recovery", "global- rustdoc-args = ["--cfg", "docsrs"] [features] -unstable = ["recovery"] default = ["std"] std = ["alloc", "secp256k1-sys/std"] # allow use of Secp256k1::new and related API that requires an allocator diff --git a/README.md b/README.md index 22f952c..86d0f80 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,11 @@ git config --local core.hooksPath githooks/ Alternatively add symlinks in your `.git/hooks` directory to any of the githooks we provide. +### Benchmarks + +We use a custom Rust compiler configuration conditional to guard the bench mark code. To run the +bench marks use: `RUSTFLAGS='--cfg=bench' cargo +nightly bench --features=recovery`. + ## Fuzzing If you want to fuzz this library, or any library which depends on it, you will diff --git a/contrib/test.sh b/contrib/test.sh index f4e088e..7933a53 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -98,9 +98,11 @@ if [ "$DO_ASAN" = true ]; then cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully" fi -# Bench -if [ "$DO_BENCH" = true ]; then - cargo bench --all --features="unstable" + +# Bench if told to, only works with non-stable toolchain (nightly, beta). +if [ "$DO_BENCH" = true ] +then + RUSTFLAGS='--cfg=bench' cargo bench --features=recovery fi exit 0 diff --git a/src/ecdh.rs b/src/ecdh.rs index 70ad705..70a5cbf 100644 --- a/src/ecdh.rs +++ b/src/ecdh.rs @@ -286,7 +286,7 @@ mod tests { } } -#[cfg(all(test, feature = "unstable"))] +#[cfg(bench)] mod benches { use test::{Bencher, black_box}; diff --git a/src/ecdsa/recovery.rs b/src/ecdsa/recovery.rs index ce9768f..9b531b0 100644 --- a/src/ecdsa/recovery.rs +++ b/src/ecdsa/recovery.rs @@ -452,7 +452,7 @@ mod tests { } } -#[cfg(all(test, feature = "unstable"))] +#[cfg(bench)] mod benches { use rand::{thread_rng, RngCore}; use test::{Bencher, black_box}; diff --git a/src/key.rs b/src/key.rs index 9971f0c..91ad391 100644 --- a/src/key.rs +++ b/src/key.rs @@ -2433,7 +2433,7 @@ mod test { } } -#[cfg(all(test, feature = "unstable"))] +#[cfg(bench)] mod benches { use test::Bencher; use std::collections::BTreeSet; diff --git a/src/lib.rs b/src/lib.rs index c2dc65f..9e336b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -155,14 +155,16 @@ #![allow(clippy::missing_safety_doc)] #![cfg_attr(all(not(test), not(feature = "std")), no_std)] -#![cfg_attr(all(test, feature = "unstable"), feature(test))] + +// Experimental features we need. #![cfg_attr(docsrs, feature(doc_cfg))] +#![cfg_attr(bench, feature(test))] #[cfg(feature = "alloc")] extern crate alloc; #[cfg(any(test, feature = "std"))] extern crate core; -#[cfg(all(test, feature = "unstable"))] +#[cfg(bench)] extern crate test; #[macro_use] @@ -1060,7 +1062,7 @@ mod tests { } } -#[cfg(all(test, feature = "unstable"))] +#[cfg(bench)] mod benches { use test::{Bencher, black_box};