mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-26 22:53:59 +00:00
use a fixed seed
This commit is contained in:
parent
7bd9e0120f
commit
ed2bd527e8
2 changed files with 6 additions and 12 deletions
15
src/lru.rs
15
src/lru.rs
|
@ -1,6 +1,5 @@
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use rand::rngs::SmallRng;
|
use rand::rngs::SmallRng;
|
||||||
use rand::FromEntropy;
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
@ -58,16 +57,17 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We always use a fixed seed for our randomness so that we have
|
||||||
|
// predictable results.
|
||||||
|
const LRU_SEED: &str = "Hello, Rustaceans";
|
||||||
|
|
||||||
impl<Node> Lru<Node>
|
impl<Node> Lru<Node>
|
||||||
where
|
where
|
||||||
Node: LruNode,
|
Node: LruNode,
|
||||||
{
|
{
|
||||||
/// Creates a new LRU list where LRU caching is disabled.
|
/// Creates a new LRU list where LRU caching is disabled.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Lru {
|
Self::with_seed(LRU_SEED)
|
||||||
green_zone: AtomicUsize::new(0),
|
|
||||||
data: Mutex::new(LruData::new()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(test), allow(dead_code))]
|
#[cfg_attr(not(test), allow(dead_code))]
|
||||||
|
@ -137,11 +137,6 @@ impl<Node> LruData<Node>
|
||||||
where
|
where
|
||||||
Node: LruNode,
|
Node: LruNode,
|
||||||
{
|
{
|
||||||
fn new() -> Self {
|
|
||||||
Self::with_rng(SmallRng::from_entropy())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(not(test), allow(dead_code))]
|
|
||||||
fn with_seed(seed_str: &str) -> Self {
|
fn with_seed(seed_str: &str) -> Self {
|
||||||
Self::with_rng(rng_with_seed(seed_str))
|
Self::with_rng(rng_with_seed(seed_str))
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ impl LruNode for TestNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const LRU_SEED: &str = "Hello, Rustaceans";
|
|
||||||
const PICK_SEED: &str = "Wippity WIP";
|
const PICK_SEED: &str = "Wippity WIP";
|
||||||
|
|
||||||
/// Randomly requests nodes and compares the performance of a
|
/// Randomly requests nodes and compares the performance of a
|
||||||
|
@ -48,7 +47,7 @@ fn compare(
|
||||||
// it. When the capacity is exceed, we can pop the oldest.
|
// it. When the capacity is exceed, we can pop the oldest.
|
||||||
let mut oracle = LinkedHashMap::new();
|
let mut oracle = LinkedHashMap::new();
|
||||||
|
|
||||||
let lru = Lru::with_seed(LRU_SEED);
|
let lru = Lru::with_seed(super::LRU_SEED);
|
||||||
lru.set_lru_capacity(capacity);
|
lru.set_lru_capacity(capacity);
|
||||||
|
|
||||||
let nodes: Vec<_> = (0..num_nodes).map(|i| TestNode::new(i)).collect();
|
let nodes: Vec<_> = (0..num_nodes).map(|i| TestNode::new(i)).collect();
|
||||||
|
|
Loading…
Reference in a new issue