Amanieu / parking_lot

Compact and efficient synchronization primitives for Rust. Also provides an API for creating custom synchronization primitives.
Apache License 2.0
2.76k stars 217 forks source link

CondVar is slower than std version #448

Open chenfengyuan opened 4 months ago

chenfengyuan commented 4 months ago

code use parking_lot code use std

After cargo build -r and run, I have below results. version duration
parking_lot 34.016281622s
std 6.342443319s

Version: rust 1.79.0 parking_lot v0.12.3

Benchmark results: rust 1.79.0 commit id ca920b3 cargo run --bin mutex --release -- 9:36:9 5 5 2 2

- Running with 9 threads
- 5 iterations inside lock, 5 iterations outside lock
- 2 seconds per test
        name         |    average     |     median     |    std.dev.
parking_lot::Mutex   |    688.961 kHz |    686.070 kHz |    157.593 kHz
std::sync::Mutex     |   1056.229 kHz |   1066.855 kHz |     60.092 kHz
pthread_mutex_t      |   1472.396 kHz |   1442.833 kHz |    138.366 kHz
- Running with 18 threads
        name         |    average     |     median     |    std.dev.
parking_lot::Mutex   |     48.460 kHz |     48.602 kHz |      4.002 kHz
std::sync::Mutex     |    521.675 kHz |    530.139 kHz |     28.304 kHz
pthread_mutex_t      |    734.650 kHz |    731.346 kHz |     38.607 kHz
- Running with 27 threads
        name         |    average     |     median     |    std.dev.
parking_lot::Mutex   |     24.781 kHz |     24.858 kHz |      0.475 kHz
std::sync::Mutex     |    340.293 kHz |    341.380 kHz |     21.122 kHz
pthread_mutex_t      |    485.667 kHz |    484.665 kHz |     25.619 kHz
- Running with 36 threads
        name         |    average     |     median     |    std.dev.
parking_lot::Mutex   |     18.455 kHz |     19.806 kHz |      1.716 kHz
std::sync::Mutex     |    255.091 kHz |    256.855 kHz |     16.656 kHz
pthread_mutex_t      |    362.141 kHz |    360.492 kHz |     23.749 kHz