-
-
Save ajgappmark/b160a50fb77449f199bbeb75d464d719 to your computer and use it in GitHub Desktop.
Compare different grep-like methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment