You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use crate spin 0.4.6 and find that the spin lock has a better performance than the standard lock.
In our case, we can't hold the lock for a long time, so using spin has a great benefit.
#[bench]fnbench_lock_write_map(b:&mutBencher){let m = HashMap::with_capacity(100);let l = Arc::new(RwLock::new(m));
b.iter(||{letmut a = l.write().unwrap();
a.insert(1,1);})}#[bench]fnbench_spinlock_write_map(b:&mutBencher){let m = HashMap::with_capacity(100);let l = Arc::new(spin::RwLock::new(m));
b.iter(||{letmut a = l.write();
a.insert(1,1);})}#[bench]fnbench_lock_read_map(b:&mutBencher){letmut m = HashMap::with_capacity(100);
m.insert(1,1);let l = Arc::new(RwLock::new(m));
b.iter(||{let a = l.read().unwrap();
a.get(&1).unwrap();})}#[bench]fnbench_spinlock_read_map(b:&mutBencher){letmut m = HashMap::with_capacity(100);
m.insert(1,1);let l = Arc::new(spin::RwLock::new(m));
b.iter(||{letmut a = l.read();
a.get(&1).unwrap();})}
test tests::bench_lock_read_map ... bench: 47 ns/iter (+/- 4)
test tests::bench_lock_write_map ... bench: 45 ns/iter (+/- 4)
test tests::bench_spinlock_read_map ... bench: 17 ns/iter (+/- 3)
test tests::bench_spinlock_write_map ... bench: 15 ns/iter (+/- 2)
The text was updated successfully, but these errors were encountered:
I use crate spin 0.4.6 and find that the spin lock has a better performance than the standard lock.
In our case, we can't hold the lock for a long time, so using spin has a great benefit.
The text was updated successfully, but these errors were encountered: