mirror of
https://github.com/ellie/atuin.git
synced 2024-09-11 21:18:22 +03:00
perf(search): benchmark smart sort (#2202)
This commit is contained in:
parent
fd3aca7cb3
commit
1201caee5c
51
Cargo.lock
generated
51
Cargo.lock
generated
@ -370,6 +370,7 @@ dependencies = [
|
||||
"base64 0.22.1",
|
||||
"crossterm",
|
||||
"directories",
|
||||
"divan",
|
||||
"eyre",
|
||||
"fs-err",
|
||||
"futures-util",
|
||||
@ -377,6 +378,7 @@ dependencies = [
|
||||
"interim",
|
||||
"itertools 0.12.1",
|
||||
"log",
|
||||
"rand",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@ -384,6 +386,7 @@ dependencies = [
|
||||
"time",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-tree",
|
||||
"unicode-segmentation",
|
||||
"unicode-width",
|
||||
"uuid",
|
||||
@ -765,6 +768,7 @@ dependencies = [
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
"terminal_size",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -858,6 +862,12 @@ dependencies = [
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "condtype"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af"
|
||||
|
||||
[[package]]
|
||||
name = "config"
|
||||
version = "0.13.4"
|
||||
@ -1172,6 +1182,31 @@ dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "divan"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0d567df2c9c2870a43f3f2bd65aaeb18dbce1c18f217c3e564b4fbaeb3ee56c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"clap",
|
||||
"condtype",
|
||||
"divan-macros",
|
||||
"libc",
|
||||
"regex-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "divan-macros"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27540baf49be0d484d8f0130d7d8da3011c32a44d4fc873368154f1510e574a2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dotenvy"
|
||||
version = "0.15.7"
|
||||
@ -2944,6 +2979,12 @@ dependencies = [
|
||||
"regex-syntax 0.8.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-lite"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.29"
|
||||
@ -3888,6 +3929,16 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "terminal_size"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7"
|
||||
dependencies = [
|
||||
"rustix",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.61"
|
||||
|
@ -39,3 +39,12 @@ tracing = "0.1"
|
||||
uuid = { workspace = true }
|
||||
unicode-segmentation = "1.11.0"
|
||||
sysinfo = "0.30.7"
|
||||
|
||||
[dev-dependencies]
|
||||
tracing-tree = "0.3"
|
||||
divan = "0.1.14"
|
||||
rand = { workspace = true }
|
||||
|
||||
[[bench]]
|
||||
name = "smart_sort"
|
||||
harness = false
|
||||
|
35
crates/atuin-history/benches/smart_sort.rs
Normal file
35
crates/atuin-history/benches/smart_sort.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use atuin_client::history::History;
|
||||
use atuin_history::sort::sort;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
fn main() {
|
||||
// Run registered benchmarks.
|
||||
divan::main();
|
||||
}
|
||||
|
||||
// Smart sort usually runs on 200 entries, test on a few sizes
|
||||
#[divan::bench(args=[100, 200, 400, 800, 1600, 10000])]
|
||||
fn smart_sort(lines: usize) {
|
||||
// benchmark a few different sizes of "history"
|
||||
// first we need to generate some history. This will use a whole bunch of memory, sorry
|
||||
let mut rng = rand::thread_rng();
|
||||
let now = time::OffsetDateTime::now_utc().unix_timestamp();
|
||||
|
||||
let possible_commands = ["echo", "ls", "cd", "grep", "atuin", "curl"];
|
||||
let mut commands = Vec::<History>::with_capacity(lines);
|
||||
|
||||
for _ in 0..lines {
|
||||
let command = possible_commands[rng.gen_range(0..possible_commands.len())];
|
||||
|
||||
let command = History::import()
|
||||
.command(command)
|
||||
.timestamp(time::OffsetDateTime::from_unix_timestamp(rng.gen_range(0..now)).unwrap())
|
||||
.build()
|
||||
.into();
|
||||
|
||||
commands.push(command);
|
||||
}
|
||||
|
||||
let _ = sort("curl", commands);
|
||||
}
|
@ -1 +1,2 @@
|
||||
pub mod sort;
|
||||
pub mod stats;
|
||||
|
@ -21,7 +21,6 @@ mod engines;
|
||||
mod history_list;
|
||||
mod inspector;
|
||||
mod interactive;
|
||||
mod sort;
|
||||
|
||||
pub use duration::format_duration_into;
|
||||
|
||||
|
@ -31,7 +31,6 @@ use super::{
|
||||
cursor::Cursor,
|
||||
engines::{SearchEngine, SearchState},
|
||||
history_list::{HistoryList, ListState, PREFIX_LENGTH},
|
||||
sort,
|
||||
};
|
||||
|
||||
use crate::{command::client::search::engines, VERSION};
|
||||
@ -96,7 +95,10 @@ impl State {
|
||||
self.results_len = results.len();
|
||||
|
||||
if smart_sort {
|
||||
Ok(sort::sort(self.search.input.as_str(), results))
|
||||
Ok(atuin_history::sort::sort(
|
||||
self.search.input.as_str(),
|
||||
results,
|
||||
))
|
||||
} else {
|
||||
Ok(results)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user