Switch sr-arithmetic benchmarking to criterion (#3902)

* Change DefaultMaxDepth from 1024 to 32

* Switch sr-arithmetic benchmarking to criterion

* Update core/sr-arithmetic/Cargo.toml

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update core/sr-arithmetic/benches/bench.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Test on variable limb lengths

* Change license

* Rework division
This commit is contained in:
Ashley
2019-10-29 12:47:27 +00:00
committed by Bastian Köcher
parent 057636fd1f
commit ae42db6049
7 changed files with 87 additions and 86 deletions
@@ -561,8 +561,6 @@ impl From<Double> for BigUint {
#[cfg(test)]
pub mod tests {
use super::*;
#[cfg(feature = "bench")]
use test::Bencher;
fn with_limbs(n: usize) -> BigUint {
BigUint { digits: vec![1; n] }
@@ -734,82 +732,4 @@ pub mod tests {
assert_eq!(b.clone().div_unit(7), BigUint::from(((B + 100) / 7) as Single));
}
#[cfg(feature = "bench")]
fn random_big_uint(size: usize) -> BigUint {
use rand::Rng;
let mut rng = rand::thread_rng();
let digits = (0..size).map(|_| rng.gen_range(0, Single::max_value())).collect();
BigUint { digits }
}
#[cfg(feature = "bench")]
#[bench]
fn bench_addition_2_digit(bencher: &mut Bencher) {
let a = random_big_uint(2);
let b = random_big_uint(2);
bencher.iter(|| {
let _ = a.clone().add(&b);
});
}
#[cfg(feature = "bench")]
#[bench]
fn bench_addition_4_digit(bencher: &mut Bencher) {
let a = random_big_uint(4);
let b = random_big_uint(4);
bencher.iter(|| {
let _ = a.clone().add(&b);
});
}
#[cfg(feature = "bench")]
#[bench]
fn bench_subtraction_2_digit(bencher: &mut Bencher) {
let a = random_big_uint(2);
let b = random_big_uint(2);
bencher.iter(|| {
let _ = a.clone().sub(&b);
});
}
#[cfg(feature = "bench")]
#[bench]
fn bench_subtraction_4_digit(bencher: &mut Bencher) {
let a = random_big_uint(4);
let b = random_big_uint(4);
bencher.iter(|| {
let _ = a.clone().sub(&b);
});
}
#[cfg(feature = "bench")]
#[bench]
fn bench_multiplication_2_digit(bencher: &mut Bencher) {
let a = random_big_uint(2);
let b = random_big_uint(2);
bencher.iter(|| {
let _ = a.clone().mul(&b);
});
}
#[cfg(feature = "bench")]
#[bench]
fn bench_multiplication_4_digit(bencher: &mut Bencher) {
let a = random_big_uint(4);
let b = random_big_uint(4);
bencher.iter(|| {
let _ = a.clone().mul(&b);
});
}
#[cfg(feature = "bench")]
#[bench]
fn bench_division_4_digit(bencher: &mut Bencher) {
let a = random_big_uint(4);
let b = random_big_uint(2);
bencher.iter(|| {
let _ = a.clone().div(&b, true);
});
}
}
-4
View File
@@ -18,10 +18,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
// to allow benchmarking
#![cfg_attr(feature = "bench", feature(test))]
#[cfg(feature = "bench")] extern crate test;
/// Copied from `sr-primitives` and documented there.
#[cfg(test)]
macro_rules! assert_eq_error_rate {