Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if ! which python3 >/dev/null 2>&1; then
- echo 'python3 required'
- fi
- if [ -z "$1" ]; then
- echo "greptest.sh <regex|string>"; exit 1
- fi
- mytime () {
- start=`date +%s.%N`
- $@ >/dev/null 2>&1
- end=`date +%s.%N`
- echo $(calc "$end - $start")
- }
- calc () {
- python3 -c "print($1)"
- }
- get_time () {
- out=$(mytime $@)
- printf "%s\n" $out
- }
- test_cmd() {
- limit=$1; total=0.0
- for i in $(seq 1 $limit); do
- val=$(get_time "${@:2}" "${string}")
- total=$(calc "$total + $val")
- done
- echo $(calc "$total / $limit")
- }
- string=$1
- rounds=100
- printf 'grep: %s\n' $(test_cmd $rounds grep -r -E)
- printf 'git grep: %s\n' $(test_cmd $rounds git grep -E)
- printf 'rg: %s\n' $(test_cmd $rounds rg)
- printf 'ack: %s\n' $(test_cmd $rounds ack)
- printf 'ag: %s\n' $(test_cmd $rounds ag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement