mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-09 01:14:29 +01:00
Markdown (and JSON) reports
This commit is contained in:
parent
ea2faf45e4
commit
b12503a46a
1
tests/benchmarks/.gitignore
vendored
Normal file
1
tests/benchmarks/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/benchmark-results
|
62
tests/benchmarks/run-benchmarks.sh
vendored
62
tests/benchmarks/run-benchmarks.sh
vendored
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
|
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
|
||||||
|
|
||||||
# Check that Hyperfine is installed.
|
# Check that Hyperfine is installed.
|
||||||
@ -19,16 +20,28 @@ get_cargo_target_dir() {
|
|||||||
cargo metadata --no-deps --format-version 1 | jq -r .target_directory
|
cargo metadata --no-deps --format-version 1 | jq -r .target_directory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
heading() {
|
||||||
|
bold=$(tput bold)$(tput setaf 220)
|
||||||
|
normal=$(tput sgr0)
|
||||||
|
echo
|
||||||
|
printf "\n%s%s%s\n\n" "$bold" "$1" "$normal"
|
||||||
|
|
||||||
|
echo -e "\n### $1\n" >> "$REPORT"
|
||||||
|
}
|
||||||
|
|
||||||
|
RESULT_DIR="benchmark-results"
|
||||||
|
REPORT="$RESULT_DIR/report.md"
|
||||||
|
|
||||||
TARGET_DIR="$(get_cargo_target_dir)"
|
TARGET_DIR="$(get_cargo_target_dir)"
|
||||||
TARGET_DEBUG="${TARGET_DIR}/debug/bat"
|
|
||||||
TARGET_RELEASE="${TARGET_DIR}/release/bat"
|
TARGET_RELEASE="${TARGET_DIR}/release/bat"
|
||||||
|
|
||||||
|
WARMUP_COUNT=3
|
||||||
|
|
||||||
# Determine which target to benchmark.
|
# Determine which target to benchmark.
|
||||||
BAT=''
|
BAT=''
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
--system) BAT="bat" ;;
|
--system) BAT="bat" ;;
|
||||||
--debug) BAT="$TARGET_DEBUG" ;;
|
|
||||||
--release) BAT="$TARGET_RELEASE" ;;
|
--release) BAT="$TARGET_RELEASE" ;;
|
||||||
--bat=*) BAT="${arg:6}" ;;
|
--bat=*) BAT="${arg:6}" ;;
|
||||||
esac
|
esac
|
||||||
@ -36,37 +49,48 @@ done
|
|||||||
|
|
||||||
if [[ -z "$BAT" ]]; then
|
if [[ -z "$BAT" ]]; then
|
||||||
echo "A build of 'bat' must be specified for benchmarking."
|
echo "A build of 'bat' must be specified for benchmarking."
|
||||||
echo "You can use '--system', '--debug', or '--release'."
|
echo "You can use '--system', '--release' or '--bat=path/to/bat'."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure that the target is built.
|
|
||||||
if ! command -v "$BAT" &>/dev/null; then
|
if ! command -v "$BAT" &>/dev/null; then
|
||||||
echo "Could not find the build of bat to benchmark."
|
echo "Could not find the build of bat to benchmark ($BAT)."
|
||||||
case "$BAT" in
|
case "$BAT" in
|
||||||
"bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
|
"bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
|
||||||
"$TARGET_DEBUG") echo "Make you sure to 'cargo build' first." ;;
|
|
||||||
"$TARGET_RELEASE") echo "Make you sure to 'cargo build --release' first." ;;
|
"$TARGET_RELEASE") echo "Make you sure to 'cargo build --release' first." ;;
|
||||||
esac
|
esac
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run the benchmark.
|
# Run the benchmarks
|
||||||
echo "### Startup time"
|
mkdir -p "$RESULT_DIR"
|
||||||
echo
|
rm -f "$RESULT_DIR"/*.md
|
||||||
|
|
||||||
hyperfine --warmup 3 "$BAT"
|
echo "## \`bat\` benchmark results" >> "$REPORT"
|
||||||
|
|
||||||
echo
|
heading "Startup time"
|
||||||
echo "### Plain text"
|
hyperfine \
|
||||||
echo
|
"$BAT" \
|
||||||
|
--warmup "$WARMUP_COUNT" \
|
||||||
|
--export-markdown "$RESULT_DIR/startup-time.md" \
|
||||||
|
--export-json "$RESULT_DIR/startup-time.json"
|
||||||
|
cat "$RESULT_DIR/startup-time.md" >> "$REPORT"
|
||||||
|
|
||||||
hyperfine --warmup 3 "$(printf "%q" "$BAT") --language txt --paging=never 'test-src/jquery-3.3.1.js'"
|
heading "Plain text speed"
|
||||||
|
hyperfine \
|
||||||
echo
|
"$(printf "%q" "$BAT") --language txt --paging=never 'test-src/jquery-3.3.1.js'" \
|
||||||
echo "### Time to syntax-highlight large files"
|
--warmup "$WARMUP_COUNT" \
|
||||||
echo
|
--export-markdown "$RESULT_DIR/plain-text-speed.md" \
|
||||||
|
--export-json "$RESULT_DIR/plain-text-speed.json"
|
||||||
|
cat "$RESULT_DIR/plain-text-speed.md" >> "$REPORT"
|
||||||
|
|
||||||
for SRC in test-src/*; do
|
for SRC in test-src/*; do
|
||||||
hyperfine --warmup 3 "$(printf "%q" "$BAT") --style=full --color=always --paging=never $(printf "%q" "$SRC")"
|
filename="$(basename "$SRC")"
|
||||||
|
heading "Syntax highlighting speed: \`$filename\`"
|
||||||
|
|
||||||
|
hyperfine --warmup "$WARMUP_COUNT" \
|
||||||
|
"$(printf "%q" "$BAT") --style=full --color=always --paging=never $(printf "%q" "$SRC")" \
|
||||||
|
--export-markdown "$RESULT_DIR/syntax-highlighting-speed-${filename}.md" \
|
||||||
|
--export-json "$RESULT_DIR/syntax-highlighting-speed-${filename}.json"
|
||||||
|
cat "$RESULT_DIR/syntax-highlighting-speed-${filename}.md" >> "$REPORT"
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user