add bench test
@@ -178,6 +178,9 @@ mod test {
use std::ops::Deref;
use futures_util::StreamExt;
use crate::sync::sync_map::SyncMap;
+ use std::time::SystemTime;
+ use chrono::Local;
+
#[test]
fn test_map() {
@@ -213,4 +216,34 @@ mod test {
}
});
}
+
+
+ //bench on windows10 40 nano/op. It depends on the runtime(tokio/async_std) speed
+ //test command:
+ //cargo test --release --color=always --package rbatis-core --lib sync::sync_map::test::bench_test --no-fail-fast -- --exact -Z unstable-options --format=json --show-output
+ #[test]
+ fn bench_test(){
+ let m = Arc::new(SyncMap::new());
+ async_std::task::block_on(async {
+ let s = m.insert(1, "default".to_string()).await;
+ drop(s);
+
+ let total = 100000;
+ let now=Local::now().timestamp_millis();
+ for current in 0..total{
+ let v= m.get(&1).await;
+ if current == total - 1 {
+ let end = Local::now().timestamp_millis();
+ print_use_time(total,now as i64,end as i64);
+ break;
+ }
+ }
+ });
+ }
+
+ fn print_use_time(total: i32, start: i64, end: i64) {
+ let mut time = (end - start) as f64;
+ time = time / 1000.0;
+ println!("use Time: {} s,each:{} nano/op", time, time * 1000000000.0 / (total as f64));
+ }
}
