dgryski / semgrep-go

Go rules for semgrep and go-ruleguard
MIT License
457 stars 37 forks source link

Replace the bench Perl script with a shell script? #33

Closed ainar-g closed 3 years ago

ainar-g commented 3 years ago

As far as I can judge, the Perl script in the repo can be replaced by a fourteen-line POSIX shell script:

#!/bin/sh

# Run from the project root as:
#
#   sh ./scripts/bench.sh

set -e -u

for f in $( ls -1 -A -q *.yml )
do
    time -p semgrep -q -f "$f" . 2>&1\
        | grep -F -e 'real'\
        | awk -v f="$f" '{ printf("%s, %.3f\n", f, $2); }'
done

Example output:

$ sh ./scripts/bench.sh 
  anon-struct-args.yml, 0.680
  badexponentiation.yml, 0.660
  badnilguard.yml, 0.750
  close-sql-query-rows.yml, 1.440
  contextTODO.yml, 0.680
  […]

I could also add some parameters, like making the pattern configurable to only check a subset of rules, if anyone needs that.

If you agree, I can send a PR.

dgryski commented 3 years ago

If you'd like. This was a hacky script I used when running some of my own tests. Feel free to generalize it (even replacing it with a Go program if you want ...)