diff --git a/Cargo.toml b/Cargo.toml index 2c471fa..4a42706 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,16 @@ edition = "2018" [package.metadata.docs.rs] features = ["std", "num-bigint-std", "serde"] +[[bench]] +name = "bigrational" + [dependencies] +[dependencies.rand] +optional = true +version = "0.8" +default-features = false + [dependencies.num-bigint] optional = true version = "0.4.0" diff --git a/benches/bigrational.rs b/benches/bigrational.rs index 4a1ee3b..37e7a42 100644 --- a/benches/bigrational.rs +++ b/benches/bigrational.rs @@ -4,58 +4,29 @@ extern crate test; use num_bigint::BigInt; use num_rational::{BigRational, Ratio}; -// use num_traits::{FromPrimitive, Num, One, Zero}; use test::Bencher; mod rng; use rng::get_rng; -// allocating 'a' and 'b' is about 70ns. -// allocating BigRational(a,b) is about 970ns. -fn alloc_bench(b: &mut Bencher) { +#[bench] +fn alloc_ratio_bigint_bench(b: &mut Bencher) { use rand::RngCore; let mut rng = get_rng(); b.iter(|| { let a = BigInt::from(rng.next_u64()); let b = BigInt::from(rng.next_u64()); BigRational::new(a, b) - // (a, b) - }); -} - -fn alloc_fast_bench(b: &mut Bencher) { - use rand::RngCore; - let mut rng = get_rng(); - b.iter(|| { - let a = BigInt::from(rng.next_u64()); - let b = BigInt::from(rng.next_u64()); - BigRational::new_fast(a, b) - // (a, b) }); } -fn alloc_u64_bench(b: &mut Bencher) { +#[bench] +fn alloc_ratio_u64_bench(b: &mut Bencher) { use rand::RngCore; let mut rng = get_rng(); b.iter(|| { let a = rng.next_u64(); let b = rng.next_u64(); - Ratio::new_fast(a, b) - // (a, b) + Ratio::new(a, b) }); } - -#[bench] -fn alloc_0(b: &mut Bencher) { - alloc_bench(b); -} - -#[bench] -fn alloc_fast_0(b: &mut Bencher) { - alloc_fast_bench(b); -} - -#[bench] -fn alloc_u64_0(b: &mut Bencher) { - alloc_u64_bench(b); -}