Add a mmap benchmark

This commit is contained in:
Richard Feldman 2020-12-08 23:01:16 -05:00
parent bdf08ea5a6
commit a46a8d076b

View file

@ -308,3 +308,29 @@ where
}
}
}
#[test]
fn mmap_benchmark() {
use std::time::SystemTime;
let start_time = SystemTime::now();
let pool = Pool::with_capacity(1234567890);
let end_time = SystemTime::now();
let elapsed = end_time.duration_since(start_time).unwrap();
println!("Time to init pool: {:?}", elapsed);
// touch a bunch of pages to see how long they take to fault in
for i in 1..100 {
let start_time = SystemTime::now();
unsafe {
*pool.nodes.offset(i * 10) = [1; NODE_BYTES];
};
let end_time = SystemTime::now();
let elapsed = end_time.duration_since(start_time).unwrap();
println!("Time to touch page {}: {:?}", i, elapsed);
}
assert_eq!(pool.capacity, 128);
}