mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
performance-metrics: Add deterministic permutation helper
Add deterministic_permutation() which produces a reproducible pseudo random permutation of [0, n) using a Fisher-Yates shuffle seeded by DefaultHasher. This is used by the random read micro benchmarks to generate a fixed access pattern that is identical across runs. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
e802c0d8b9
commit
638cb3d7f2
@@ -89,6 +89,24 @@ pub fn write_iovec(buf: &[u8]) -> libc::iovec {
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a deterministic pseudo-random permutation of `[0, n)`.
|
||||
///
|
||||
/// Uses a Fisher-Yates shuffle seeded by `DefaultHasher` so the
|
||||
/// permutation is identical across runs.
|
||||
pub fn deterministic_permutation(n: usize) -> Vec<usize> {
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
let mut indices: Vec<usize> = (0..n).collect();
|
||||
for i in (1..n).rev() {
|
||||
let mut h = DefaultHasher::new();
|
||||
i.hash(&mut h);
|
||||
let j = h.finish() as usize % (i + 1);
|
||||
indices.swap(i, j);
|
||||
}
|
||||
indices
|
||||
}
|
||||
|
||||
/// Submit `count` sequential read_vectored calls at `stride`-byte intervals.
|
||||
pub fn submit_reads(async_io: &mut dyn AsyncIo, count: usize, stride: u64, iovec: &[libc::iovec]) {
|
||||
for i in 0..count {
|
||||
|
||||
Reference in New Issue
Block a user