Use the parking_lot locking primitives by faern · Pull Request #56410 · rust-lang/rust (original) (raw)
I could post some kind of benchmarks. The parking_lot
repo has a benchmark sub-crate in it that can perform some micro benchmarking of the Mutex
and RwLock
types. Please keep in mind these are micro benchmarks, and also that the numbers varies quite a lot between runs as well.
Mutex
Built using latest nightly rustc/libstd:
$ cargo +nightly run --release --bin mutex -- 2 1 0 1 2
- Running with 2 threads
- 1 iterations inside lock, 0 iterations outside lock
- 1 seconds per test
name | average | median | std.dev.
parking_lot::Mutex | 27880.651 kHz | 27643.931 kHz | 784.495 kHz
std::sync::Mutex | 5760.698 kHz | 5983.312 kHz | 244.146 kHz
pthread_mutex_t | 7557.519 kHz | 7640.839 kHz | 258.375 kHz
Built using the code currently in this PR (stage1 compiler):
$ cargo +stage1 run --release --bin mutex -- 2 1 0 1 2
- Running with 2 threads
- 1 iterations inside lock, 0 iterations outside lock
- 1 seconds per test
name | average | median | std.dev.
parking_lot::Mutex | 26761.369 kHz | 28265.800 kHz | 3176.551 kHz
std::sync::Mutex | 21122.531 kHz | 20840.200 kHz | 1490.975 kHz
pthread_mutex_t | 7654.629 kHz | 7509.882 kHz | 648.945 kHz
RwLock
Built using latest nightly rustc/libstd:
$ cargo +nightly run --release --bin rwlock -- 1 1 1 0 1 2
- Running with 1 writer threads and 1 reader threads
- 1 iterations inside lock, 0 iterations outside lock
- 1 seconds per test
parking_lot::RwLock - [write] 44619.796 kHz [read] 11551.274 kHz
seqlock::SeqLock - [write] 27633.108 kHz [read] 31532.853 kHz
std::sync::RwLock - [write] 6450.503 kHz [read] 4018.782 kHz
pthread_rwlock_t - [write] 11007.401 kHz [read] 8722.818 kHz
Built using the code currently in this PR (stage1 compiler):
$ cargo +stage1 run --release --bin rwlock -- 1 1 1 0 1 2
- Running with 1 writer threads and 1 reader threads
- 1 iterations inside lock, 0 iterations outside lock
- 1 seconds per test
parking_lot::RwLock - [write] 38818.641 kHz [read] 15724.790 kHz
seqlock::SeqLock - [write] 27193.925 kHz [read] 38514.387 kHz
std::sync::RwLock - [write] 34072.830 kHz [read] 2120.811 kHz
pthread_rwlock_t - [write] 9255.783 kHz [read] 8181.922 kHz
All of the above was on Linux.