2023-10-26 17:47:53 +00:00
|
|
|
#![allow(unused)]
|
2023-10-30 19:25:31 +00:00
|
|
|
use generational_box::*;
|
2023-10-26 17:47:53 +00:00
|
|
|
|
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
|
|
|
2023-10-30 19:25:31 +00:00
|
|
|
fn create<S: Storage<u32>>(owner: &Owner<S>) -> GenerationalBox<u32, S> {
|
2023-10-26 17:47:53 +00:00
|
|
|
owner.insert(0)
|
|
|
|
}
|
|
|
|
|
2023-10-30 19:25:31 +00:00
|
|
|
fn set_read<S: Storage<u32>>(signal: GenerationalBox<u32, S>) -> u32 {
|
2023-10-26 17:47:53 +00:00
|
|
|
signal.set(1);
|
|
|
|
*signal.read()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bench_fib(c: &mut Criterion) {
|
2023-10-30 19:25:31 +00:00
|
|
|
{
|
|
|
|
let owner = UnsyncStorage::owner();
|
|
|
|
c.bench_function("create_unsync", |b| b.iter(|| create(black_box(&owner))));
|
|
|
|
let signal = create(&owner);
|
|
|
|
c.bench_function("set_read_unsync", |b| {
|
|
|
|
b.iter(|| set_read(black_box(signal)))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
{
|
|
|
|
let owner = SyncStorage::owner();
|
|
|
|
c.bench_function("create_sync", |b| b.iter(|| create(black_box(&owner))));
|
|
|
|
let signal = create(&owner);
|
|
|
|
c.bench_function("set_read_sync", |b| b.iter(|| set_read(black_box(signal))));
|
|
|
|
}
|
2023-10-26 17:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, bench_fib);
|
|
|
|
criterion_main!(benches);
|