use std::sync::Arc;
use std::thread;
use std::time::Duration;
use fast_able::statis::Statis;
use fast_able::SyncHashMapB as SyncHashMap;
pub static RECKON_BY_SEC: once_cell::sync::Lazy<Statis> =
once_cell::sync::Lazy::new(|| Statis::new(|v| println!("one sec run sum: {v}")));
#[test]
fn bench_insert_mul_thread() {
let rw = Arc::new(SyncHashMap::new(Some(10)));
rw.insert(1, 1);
assert_eq!(rw.len(), 1);
let rw2 = rw.clone();
let rt1 = std::thread::spawn(move || {
for i in 0..5_0000_0000_u64 {
rw2.insert(i, i + 1);
RECKON_BY_SEC.add();
}
});
let rw2 = rw.clone();
let rt2 = std::thread::spawn(move || {
for i in 5_0000_0000..10_0000_0000_u64 {
rw2.insert(i, i + 1);
RECKON_BY_SEC.add();
}
});
let rw2 = rw.clone();
let rt3 = std::thread::spawn(move || {
for i in 10_0000_0000_u64..50_0000_0000_u64 {
rw2.insert(i, i + 1);
RECKON_BY_SEC.add();
}
});
rt1.join();
}
#[test]
fn bench_insert_one_thread() {
let rw = Arc::new(SyncHashMap::new(None));
rw.insert(1, 1);
assert_eq!(rw.len(), 1);
let rw2 = rw.clone();
let rt1 = std::thread::spawn(move || {
for i in 0..10000_0000 {
rw2.insert(i, i + 1);
RECKON_BY_SEC.add();
}
});
rt1.join();
}