smithay/benches/benchmark.rs
Ian Douglas Scott fe24d1bcd0 Use a thread-local for thread ID in UserDataMap::get
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.
2023-05-17 16:00:57 -07:00

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);