mirror of
https://github.com/nushell/nushell.git
synced 2025-08-15 04:42:35 +02:00
feat(std/bench) add osc 9;4
progress bar (#16245)
# Description Using `osc 9;4`, `bench` shows a progress bar or circle on supported terminals, every 10 timing rounds to not degrade performance too much. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This commit is contained in:
@ -84,6 +84,8 @@ export def main [
|
|||||||
nothing -> table<code: string, mean: duration, std: duration, ratio: float>
|
nothing -> table<code: string, mean: duration, std: duration, ratio: float>
|
||||||
nothing -> string
|
nothing -> string
|
||||||
] {
|
] {
|
||||||
|
let $num_commands = ($commands | length)
|
||||||
|
let $total_rounds = $rounds * $num_commands
|
||||||
if $setup != null { do $setup | ignore }
|
if $setup != null { do $setup | ignore }
|
||||||
|
|
||||||
let results = (
|
let results = (
|
||||||
@ -91,7 +93,7 @@ export def main [
|
|||||||
let code = $x.item
|
let code = $x.item
|
||||||
let idx = $x.index
|
let idx = $x.index
|
||||||
|
|
||||||
let bench_num = if ($commands | length) > 1 { $" ($idx + 1)"}
|
let bench_num = if $num_commands > 1 { $" ($idx + 1)"}
|
||||||
|
|
||||||
seq 1 $warmup | each {|i|
|
seq 1 $warmup | each {|i|
|
||||||
if $progress { print -n $"Warmup($bench_num): ($i) / ($warmup)\r" }
|
if $progress { print -n $"Warmup($bench_num): ($i) / ($warmup)\r" }
|
||||||
@ -104,6 +106,7 @@ export def main [
|
|||||||
|
|
||||||
let times: list<duration> = (
|
let times: list<duration> = (
|
||||||
seq 1 $rounds | each {|i|
|
seq 1 $rounds | each {|i|
|
||||||
|
if $i mod 10 == 0 { print -n $'(ansi osc)9;4;1;(($idx * $rounds + $i) / $total_rounds * 100 | into int)(ansi st)' }
|
||||||
if $progress { print -n $"Benchmark($bench_num): ($i) / ($rounds)\r" }
|
if $progress { print -n $"Benchmark($bench_num): ($i) / ($rounds)\r" }
|
||||||
|
|
||||||
if $prepare != null { $idx | do $prepare $idx | ignore }
|
if $prepare != null { $idx | do $prepare $idx | ignore }
|
||||||
@ -127,9 +130,10 @@ export def main [
|
|||||||
)
|
)
|
||||||
|
|
||||||
if $cleanup != null { do $cleanup | ignore }
|
if $cleanup != null { do $cleanup | ignore }
|
||||||
|
print -n $'(ansi osc)9;4;0(ansi st)'
|
||||||
|
|
||||||
# One benchmark
|
# One benchmark
|
||||||
if ($results | length) == 1 {
|
if $num_commands == 1 {
|
||||||
let report = $results | first
|
let report = $results | first
|
||||||
if $pretty {
|
if $pretty {
|
||||||
return $"($report.mean) +/- ($report.std)"
|
return $"($report.mean) +/- ($report.std)"
|
||||||
|
Reference in New Issue
Block a user