From c2bc8aee20911850203c6f08006cdac98fc49b07 Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Fri, 2 Apr 2021 17:20:19 +0530 Subject: [PATCH] Fix benchmarks --- benches/navigation.rs | 68 ++++++++++++++++++++++++++++++++++++++----- tests/test_input.rs | 4 +-- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/benches/navigation.rs b/benches/navigation.rs index a96fa2c..7386711 100644 --- a/benches/navigation.rs +++ b/benches/navigation.rs @@ -8,33 +8,85 @@ fn criterion_benchmark(c: &mut Criterion) { fs::File::create(format!("/tmp/xplr_bench/{}", i)).unwrap(); }); - let app = app::create() + let app = app::App::create() .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(); 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| { - 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| { - 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| { - 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| { b.iter(|| { 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() - .handle(&config::Action::Enter) }) }); } diff --git a/tests/test_input.rs b/tests/test_input.rs index 8923056..98d07d5 100644 --- a/tests/test_input.rs +++ b/tests/test_input.rs @@ -2,9 +2,9 @@ use xplr::*; #[test] 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();