sharkdp / hyperfine

A command-line benchmarking tool
Apache License 2.0
21.67k stars 349 forks source link

Add quieter markdown `stdout` export #685

Closed Neved4 closed 12 months ago

Neved4 commented 1 year ago

Currently, hyperfine allows markdown export to stdout with --export-markdown -. This also includes its regular output, requiring manual filtering.

Feature request

A better, if more involved, enhancement would be to allow doing a single hyperfine call awith configurable markdown sections. Ultimately, this will organise each benchmark below its corresponding section.

Background

When running multiple benchmarks to later be unified in a single markdown file, one needs to call hyperfine and create intermediate files, to later structure the saved outputs in an unified manner, cleaning the intermediates:

# temp.sh

hyperfine 'echo 1' --export-markdown first.md
hyperfine 'echo 2' --export-markdown second.md

printf '%s\n' '## First benchmark'
cat first.md > bench.md

printf '%s\n' '## First benchmark'
cat second.md > bench.md

rm first.md second.md

Alternatively, since hyperfine allows to export to stdout instead, we can get rid of the temporary files and filter the desired output:

# filter.sh

filter() {
    awk '/^\| Command | Mean /{p=1} p && !/^$/{print} p && /^$/{exit}'
}

{
    printf '%s\n' '## First benchmark'
    hyperfine 'echo 1' --export-markdown | filter

    printf '%s\n' '## Second benchmark'
    hyperfine 'echo 2' --export-markdown - | filter
} > bench.md

See: tukosmo-errhandle/b795a31

Overall this streamlined approach avoids temporary files, although in other scenarios the ability to suppress the regular output entirely can be more suitable, removing the need of a filtering function.

sharkdp commented 12 months ago

Did you see the --style option? In particular: --style=none

Neved4 commented 12 months ago

@sharkdp Spot on. Thanks!

Missed that, the manpage description can be a bit misleading:

Set this to 'none' to disable all the output of the tool.

Closing.