Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #!/bin/bash
  2. if ! which python3 >/dev/null 2>&1; then
  3. echo 'python3 required'
  4. fi
  5. if [ -z "$1" ]; then
  6. echo "greptest.sh <regex|string>"; exit 1
  7. fi
  8. mytime () {
  9. start=`date +%s.%N`
  10. $@ >/dev/null 2>&1
  11. end=`date +%s.%N`
  12. echo $(calc "$end - $start")
  13. }
  14. calc () {
  15. python3 -c "print($1)"
  16. }
  17. get_time () {
  18. out=$(mytime $@)
  19. printf "%s\n" $out
  20. }
  21.  
  22. test_cmd() {
  23. limit=$1; total=0.0
  24. for i in $(seq 1 $limit); do
  25. val=$(get_time "${@:2}" "${string}")
  26. total=$(calc "$total + $val")
  27. done
  28. echo $(calc "$total / $limit")
  29. }
  30.  
  31. string=$1
  32. rounds=100
  33. printf 'grep: %s\n' $(test_cmd $rounds grep -r -E)
  34. printf 'git grep: %s\n' $(test_cmd $rounds git grep -E)
  35. printf 'rg: %s\n' $(test_cmd $rounds rg)
  36. printf 'ack: %s\n' $(test_cmd $rounds ack)
  37. printf 'ag: %s\n' $(test_cmd $rounds ag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement