Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rand to 0.8 but use the SmallRng from 0.7 #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ azure-devops = { project = "jonhoo/jonhoo", pipeline = "bustle", build = "18" }
maintenance = { status = "experimental" }

[dependencies]
rand = { version = "0.7", features = ["small_rng"] }
rand = { version = "0.8" }
tracing = { version = "0.1", features = ["std"], default-features = false }
rand_pcg = "0.3"

[dev-dependencies]
tracing-subscriber = "0.2"
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ use std::{sync::Arc, time::Duration};
use rand::prelude::*;
use tracing::{debug, info, info_span};

#[cfg(all(not(target_os = "emscripten"), target_pointer_width = "64"))]
type SmallRng = rand_pcg::Pcg64Mcg;
#[cfg(not(all(not(target_os = "emscripten"), target_pointer_width = "64")))]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow why the #[cfg] is needed here — why not use the same one on all targets?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the code from rand 0.7

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see! I think I'd prefer to go the u64 path and stick with rand's SmallRng. Given that we'll probably end up with a breaking change from #7, I'm okay with breaking on this now.

type SmallRng = rand_pcg::Pcg32;

/// A workload mix configration.
///
/// The sum of the fields must add to 100.
Expand Down Expand Up @@ -292,7 +297,7 @@ impl Workload {
let total_ops = (initial_capacity as f64 * self.ops_f) as usize;

let seed = self.seed.unwrap_or_else(rand::random);
let mut rng: rand::rngs::SmallRng = rand::SeedableRng::from_seed(seed);
let mut rng: SmallRng = SeedableRng::from_seed(seed);

// NOTE: it'd be nice to include std::intrinsics::type_name::<T> here
let span = info_span!("benchmark", mix = ?self.mix, threads = self.threads);
Expand Down Expand Up @@ -325,7 +330,7 @@ impl Workload {
let mut thread_seed = [0u8; 16];
rng.fill_bytes(&mut thread_seed[..]);
generators.push(std::thread::spawn(move || {
let mut rng: rand::rngs::SmallRng = rand::SeedableRng::from_seed(thread_seed);
let mut rng: SmallRng = SeedableRng::from_seed(thread_seed);
let mut keys: Vec<<T::Handle as CollectionHandle>::Key> =
Vec::with_capacity(insert_keys_per_thread);
keys.extend((0..insert_keys_per_thread).map(|_| rng.next_u64().into()));
Expand Down