Fix benchmarks

pull/3/head
Arijit Basu 3 years ago
parent 3990200232
commit c2bc8aee20
No known key found for this signature in database
GPG Key ID: 7D7BF809E7378863

@ -8,33 +8,85 @@ fn criterion_benchmark(c: &mut Criterion) {
fs::File::create(format!("/tmp/xplr_bench/{}", i)).unwrap(); fs::File::create(format!("/tmp/xplr_bench/{}", i)).unwrap();
}); });
let app = app::create() let app = app::App::create()
.expect("failed to create app") .expect("failed to create app")
.change_directory(&"/tmp/xplr_bench".to_string()) .enqueue(app::Task::new(
1,
app::MsgIn::External(app::ExternalMsg::ChangeDirectory("/tmp/xplr_bench".into())),
None,
))
.possibly_mutate()
.unwrap(); .unwrap();
c.bench_function("focus next item", |b| { c.bench_function("focus next item", |b| {
b.iter(|| app.clone().handle(&config::Action::FocusNext)) b.iter(|| {
app.clone()
.enqueue(app::Task::new(
1,
app::MsgIn::External(app::ExternalMsg::FocusNext),
None,
))
.possibly_mutate()
.unwrap()
})
}); });
c.bench_function("focus previous item", |b| { c.bench_function("focus previous item", |b| {
b.iter(|| app.clone().handle(&config::Action::FocusPrevious)) b.iter(|| {
app.clone()
.enqueue(app::Task::new(
1,
app::MsgIn::External(app::ExternalMsg::FocusPrevious),
None,
))
.possibly_mutate()
.unwrap()
})
}); });
c.bench_function("focus first item", |b| { c.bench_function("focus first item", |b| {
b.iter(|| app.clone().handle(&config::Action::FocusFirst)) b.iter(|| {
app.clone()
.enqueue(app::Task::new(
1,
app::MsgIn::External(app::ExternalMsg::FocusFirst),
None,
))
.possibly_mutate()
.unwrap()
})
}); });
c.bench_function("focus last item", |b| { c.bench_function("focus last item", |b| {
b.iter(|| app.clone().handle(&config::Action::FocusLast)) b.iter(|| {
app.clone()
.enqueue(app::Task::new(
1,
app::MsgIn::External(app::ExternalMsg::FocusLast),
None,
))
.possibly_mutate()
.unwrap()
})
}); });
c.bench_function("leave and enter directory", |b| { c.bench_function("leave and enter directory", |b| {
b.iter(|| { b.iter(|| {
app.clone() app.clone()
.handle(&config::Action::Back) .enqueue(app::Task::new(
1,
app::MsgIn::External(app::ExternalMsg::Back),
None,
))
.possibly_mutate()
.unwrap()
.enqueue(app::Task::new(
1,
app::MsgIn::External(app::ExternalMsg::Back),
None,
))
.possibly_mutate()
.unwrap() .unwrap()
.handle(&config::Action::Enter)
}) })
}); });
} }

@ -2,9 +2,9 @@ use xplr::*;
#[test] #[test]
fn test_key_down() { fn test_key_down() {
let mut app = app::create().expect("failed to create app"); let mut app = app::App::create().expect("failed to create app");
assert_eq!(app.directory_buffer.focus, Some(0)); assert_eq!(app.focus(), Some(0));
let actions = app.actions_from_key(&input::Key::Down).unwrap(); let actions = app.actions_from_key(&input::Key::Down).unwrap();

Loading…
Cancel
Save