-
-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(search): benchmark smart sort (#2202)
- Loading branch information
Showing
7 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod sort; | ||
pub mod stats; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters