tree-sitter/script/benchmark

59 lines
1.1 KiB
Text
Raw Normal View History

#!/usr/bin/env bash
set -e
2017-07-05 17:27:32 -07:00
function usage {
cat <<-EOF
USAGE
$0 [-h] [-l language-name] [-e example-file-name] [-r repetition-count]
2017-07-05 17:27:32 -07:00
OPTIONS
-h print this message
-l run only the benchmarks for the given language
-e run only the benchmarks that parse the example file with the given name
2017-07-06 10:22:14 -07:00
-r parse each sample the given number of times (default 5)
2020-06-26 15:05:27 -07:00
-g debug
2017-07-05 17:27:32 -07:00
EOF
}
2020-06-26 15:05:27 -07:00
mode=normal
while getopts "hgl:e:r:" option; do
case ${option} in
2017-07-05 17:27:32 -07:00
h)
usage
exit
;;
2020-06-26 15:05:27 -07:00
g)
mode=debug
;;
e)
export TREE_SITTER_BENCHMARK_EXAMPLE_FILTER=${OPTARG}
;;
l)
export TREE_SITTER_BENCHMARK_LANGUAGE_FILTER=${OPTARG}
2017-07-06 10:22:14 -07:00
;;
r)
export TREE_SITTER_BENCHMARK_REPETITION_COUNT=${OPTARG}
;;
esac
done
2020-06-26 15:05:27 -07:00
if [[ "${mode}" == "debug" ]]; then
test_binary=$(
cargo bench benchmark -p tree-sitter-cli --no-run --message-format=json 2> /dev/null |\
2020-06-26 15:05:27 -07:00
jq -rs 'map(select(.target.name == "benchmark" and .executable))[0].executable'
)
env | grep TREE_SITTER
echo $test_binary
else
exec cargo bench benchmark -p tree-sitter-cli
2020-06-26 15:05:27 -07:00
fi