Skip to content

Commit

Permalink
seed tests with u64 for platform consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Mar 5, 2021
1 parent 46aa212 commit 998d4cb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 39 deletions.
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ build = "build.rs"
exclude = ["/bors.toml", "/ci/*", "/.github/*"]
edition = "2018"

[features]
default = ["std"]
std = ["num-integer/std", "num-traits/std"]

[package.metadata.docs.rs]
features = ["std", "serde", "rand", "quickcheck", "arbitrary"]

Expand Down Expand Up @@ -66,9 +70,8 @@ optional = true
version = "0.4"
default-features = false

[features]
default = ["std"]
std = ["num-integer/std", "num-traits/std"]

[build-dependencies]
autocfg = "1"

[dev-dependencies]
rand_xorshift = "0.3"
12 changes: 4 additions & 8 deletions benches/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ extern crate test;

use num_bigint::{BigInt, BigUint, RandBigInt};
use num_traits::{FromPrimitive, Num, One, Zero};
use rand::rngs::StdRng;
use rand::SeedableRng;
use rand::prelude::*;
use rand_xorshift::XorShiftRng;
use std::mem::replace;
use test::Bencher;

fn get_rng() -> StdRng {
let mut seed = [0; 32];
for i in 1..32 {
seed[usize::from(i)] = i;
}
SeedableRng::from_seed(seed)
fn get_rng() -> impl Rng {
XorShiftRng::seed_from_u64(0x1234_5678_9abc_def0)
}

fn multiply_bench(b: &mut Bencher, xbits: u64, ybits: u64) {
Expand Down
12 changes: 4 additions & 8 deletions benches/gcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ extern crate test;
use num_bigint::{BigUint, RandBigInt};
use num_integer::Integer;
use num_traits::Zero;
use rand::rngs::StdRng;
use rand::SeedableRng;
use rand::prelude::*;
use rand_xorshift::XorShiftRng;
use test::Bencher;

fn get_rng() -> StdRng {
let mut seed = [0; 32];
for i in 1..32 {
seed[usize::from(i)] = i;
}
SeedableRng::from_seed(seed)
fn get_rng() -> impl Rng {
XorShiftRng::seed_from_u64(0x1234_5678_9abc_def0)
}

fn bench(b: &mut Bencher, bits: u64, gcd: fn(&BigUint, &BigUint) -> BigUint) {
Expand Down
12 changes: 4 additions & 8 deletions benches/roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
extern crate test;

use num_bigint::{BigUint, RandBigInt};
use rand::rngs::StdRng;
use rand::SeedableRng;
use rand::prelude::*;
use rand_xorshift::XorShiftRng;
use test::Bencher;

// The `big64` cases demonstrate the speed of cases where the value
Expand All @@ -16,12 +16,8 @@ use test::Bencher;
//
// The `big2k` and `big4k` cases are too big for `f64`, and use a simpler guess.

fn get_rng() -> StdRng {
let mut seed = [0; 32];
for i in 1..32 {
seed[usize::from(i)] = i;
}
SeedableRng::from_seed(seed)
fn get_rng() -> impl Rng {
XorShiftRng::seed_from_u64(0x1234_5678_9abc_def0)
}

fn check(x: &BigUint, n: u32) {
Expand Down
5 changes: 1 addition & 4 deletions ci/big_rand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ edition = "2018"

[dependencies]
num-traits = "0.2.11"
rand = "0.8"
rand_chacha = "0.3"
rand_isaac = "0.3"
rand_xorshift = "0.3"

[dependencies.num-bigint]
features = ["rand"]
path = "../.."

[dependencies.rand]
features = ["small_rng"]
version = "0.8"
10 changes: 3 additions & 7 deletions ci/big_rand/src/torture.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use num_bigint::RandBigInt;
use num_traits::Zero;
use rand::prelude::*;
use rand::rngs::SmallRng;
use rand_xorshift::XorShiftRng;

fn get_rng() -> SmallRng {
let seed = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32,
];
SmallRng::from_seed(seed)
fn get_rng() -> impl Rng {
XorShiftRng::seed_from_u64(0x1234_5678_9abc_def0)
}

fn test_mul_divide_torture_count(count: usize) {
Expand Down

0 comments on commit 998d4cb

Please sign in to comment.