//! sign-dist: time secp256k1 signing and keep every sample, so the distribution can be drawn. //! //! The same timed loop as sentinel-bench's emit_benchmark_json in the zerocopy workspace: the same key bytes, //! the same 256-byte message, the same 1,000 warm-up signatures. It writes one duration per line, in //! nanoseconds, in the order taken. Used for the histogram on https://zerocopy.systems/latency. //! //! Cargo.toml for a crate named sign-dist (the release profile matches the zerocopy workspace's): //! //! [package] //! name = "sign-dist" //! version = "0.1.0" //! edition = "2021" //! //! [dependencies] //! k256 = { version = "=0.13.4", features = ["ecdsa", "sha256"] } //! //! [profile.release] //! opt-level = 3 //! strip = true //! lto = "fat" //! panic = "abort" //! codegen-units = 1 //! overflow-checks = true //! //! Put this file at src/main.rs, then: //! cargo build --release //! ./target/release/sign-dist 200000 > samples.txt use k256::ecdsa::{signature::Signer, Signature, SigningKey}; use std::io::Write; use std::time::Instant; fn main() { let n: usize = std::env::args().nth(1).and_then(|v| v.parse().ok()).unwrap_or(200_000); let signing_key = SigningKey::from_bytes(&[42u8; 32].into()).expect("static key bytes are valid"); let message = [0xABu8; 256]; for _ in 0..1000 { let _: Signature = signing_key.sign(&message); } let mut samples: Vec = Vec::with_capacity(n); for _ in 0..n { let t0 = Instant::now(); let s: Signature = signing_key.sign(&message); samples.push(t0.elapsed().as_nanos() as u64); std::hint::black_box(s); } let out = std::io::stdout(); let mut w = std::io::BufWriter::new(out.lock()); for s in samples { writeln!(w, "{s}").unwrap(); } }