xplr/benches/navigation.rs
Arijit Basu 2596c0c4c3 Remove task priority
Since we are now blocking on task inputs, the priority is no longer
required.
2021-04-09 15:29:05 +05:30

81 lines
2.3 KiB
Rust

use criterion::{criterion_group, criterion_main, Criterion};
use std::fs;
use xplr::*;
fn criterion_benchmark(c: &mut Criterion) {
fs::create_dir_all("/tmp/xplr_bench").unwrap();
(1..10000).for_each(|i| {
fs::File::create(format!("/tmp/xplr_bench/{}", i)).unwrap();
});
let app = app::App::create("/tmp/xplr_bench".into())
.expect("failed to create app")
.handle_task(app::Task::new(
app::MsgIn::External(app::ExternalMsg::ChangeDirectory("/tmp/xplr_bench".into())),
None,
))
.unwrap();
c.bench_function("focus next item", |b| {
b.iter(|| {
app.clone()
.handle_task(app::Task::new(
app::MsgIn::External(app::ExternalMsg::FocusNext),
None,
))
.unwrap()
})
});
c.bench_function("focus previous item", |b| {
b.iter(|| {
app.clone()
.handle_task(app::Task::new(
app::MsgIn::External(app::ExternalMsg::FocusPrevious),
None,
))
.unwrap()
})
});
c.bench_function("focus first item", |b| {
b.iter(|| {
app.clone()
.handle_task(app::Task::new(
app::MsgIn::External(app::ExternalMsg::FocusFirst),
None,
))
.unwrap()
})
});
c.bench_function("focus last item", |b| {
b.iter(|| {
app.clone()
.handle_task(app::Task::new(
app::MsgIn::External(app::ExternalMsg::FocusLast),
None,
))
.unwrap()
})
});
c.bench_function("leave and enter directory", |b| {
b.iter(|| {
app.clone()
.handle_task(app::Task::new(
app::MsgIn::External(app::ExternalMsg::Back),
None,
))
.unwrap()
.handle_task(app::Task::new(
app::MsgIn::External(app::ExternalMsg::Enter),
None,
))
.unwrap()
})
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);