mirror of
https://github.com/Smithay/smithay.git
synced 2024-09-28 03:21:14 +02:00
fe24d1bcd0
Profiling suggests the compositor was spending a surprising amount of time getting the thread ID. It seems `thread::current().id()` is a bit slow. Calling this once and storing the result in a thread-local seems to make the performance roughly match the thread-safe variant, if the benchmark added here is accurate.
18 lines
625 B
Rust
18 lines
625 B
Rust
use criterion::{criterion_group, criterion_main, Criterion};
|
|
use smithay::utils::user_data::UserDataMap;
|
|
|
|
fn criterion_benchmark(c: &mut Criterion) {
|
|
c.bench_function("UserDataMap::get", |b| {
|
|
let udata_map = UserDataMap::new();
|
|
udata_map.insert_if_missing(|| 17i32);
|
|
b.iter(|| udata_map.get::<i32>())
|
|
});
|
|
c.bench_function("UserDataMap::get threadsafe", |b| {
|
|
let udata_map = UserDataMap::new();
|
|
udata_map.insert_if_missing_threadsafe(|| 17i32);
|
|
b.iter(|| udata_map.get::<i32>())
|
|
});
|
|
}
|
|
|
|
criterion_group!(benches, criterion_benchmark);
|
|
criterion_main!(benches);
|