| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | # Measures impact of a Git commit (or multiple commits) on generated parsers' |
| 4 | # speed and size. Makes sense to use only on PEG.js Git repository checkout. |
| 5 | |
| 6 | set -e |
| 7 | export LC_ALL=C |
| 8 | |
| 9 | # Measurement |
| 10 | |
| 11 | preparescip-shell shell shell-project 0.0.0 prepare().() { |
| 12 | gitscip-shell system . . git. checkout --quiet "$1" |
| 13 | } |
| 14 | |
| 15 | run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().() { |
| 16 | echoscip-shell system . . echo. $(makescip-shell system . . make. benchmark | awkscip-shell system . . awk. 'BEGIN { FS = " *│ *" } /Total/ { split($5, a, " "); print a[1] }') |
| 17 | } |
| 18 | |
| 19 | measure_speedscip-shell shell shell-project 0.0.0 measure_speed().() { |
| 20 | bc <<-EOT |
| 21 | scale = 2 |
| 22 | ($(run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().) + $(run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().) + $(run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().) + $(run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().) + $(run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().)) / 5 |
| 23 | EOT |
| 24 | } |
| 25 | |
| 26 | measure_sizescip-shell shell shell-project 0.0.0 measure_size().() { |
| 27 | for file in examples/*.pegjs; do |
| 28 | bin/pegjs "$file" |
| 29 | done |
| 30 | |
| 31 | echoscip-shell system . . echo. $(catscip-shell system . . cat. examples/*.js | wcscip-shell system . . wc. -c) |
| 32 | |
| 33 | rmscip-shell system . . rm. examples/*.js |
| 34 | } |
| 35 | |
| 36 | differencescip-shell shell shell-project 0.0.0 difference().() { |
| 37 | bc <<-EOT |
| 38 | scale = 4 |
| 39 | ($2 / $1 - 1) * 100 |
| 40 | EOT |
| 41 | } |
| 42 | |
| 43 | # Helpers |
| 44 | |
| 45 | print_resultsscip-shell shell shell-project 0.0.0 print_results().() { |
| 46 | echoscip-shell system . . echo. |
| 47 | |
| 48 | echoscip-shell system . . echo. "Speed impact" |
| 49 | echoscip-shell system . . echo. "------------" |
| 50 | echoscip-shell system . . echo. "Before: $1 kB/s" |
| 51 | echoscip-shell system . . echo. "After: $2 kB/s" |
| 52 | printfscip-shell system . . printf. "Difference: %0.2f%%\n" $(differencescip-shell shell shell-project 0.0.0 difference(). $1 $2) |
| 53 | |
| 54 | echoscip-shell system . . echo. |
| 55 | |
| 56 | echoscip-shell system . . echo. "Size impact" |
| 57 | echoscip-shell system . . echo. "-----------" |
| 58 | echoscip-shell system . . echo. "Before: $3 b" |
| 59 | echoscip-shell system . . echo. "After: $4 b" |
| 60 | printfscip-shell system . . printf. "Difference: %0.2f%%\n" $(differencescip-shell shell shell-project 0.0.0 difference(). $3 $4) |
| 61 | |
| 62 | echoscip-shell system . . echo. |
| 63 | |
| 64 | echoscip-shell system . . echo. "(Measured by /tools/impact with Node.js $(nodescip-shell system . . node. --version) on $(unamescip-shell system . . uname. -mrs).)" |
| 65 | } |
| 66 | |
| 67 | print_usagescip-shell shell shell-project 0.0.0 print_usage().() { |
| 68 | echoscip-shell system . . echo. "Usage:" |
| 69 | echoscip-shell system . . echo. " $0 <commit>" |
| 70 | echoscip-shell system . . echo. " $0 <commit_before> <commit_after>" |
| 71 | echoscip-shell system . . echo. |
| 72 | echoscip-shell system . . echo. "Measures impact of a Git commit (or multiple commits) on generated parsers'" |
| 73 | echoscip-shell system . . echo. "speed and size. Makes sense to use only on PEG.js Git repository checkout." |
| 74 | } |
| 75 | |
| 76 | cd_to_rootscip-shell shell shell-project 0.0.0 cd_to_root().() { |
| 77 | if [scip-shell system . . `[`. -L "$0" ]; then |
| 78 | THIS_FILE=$(readlinkscip-shell system . . readlink. "$0") |
| 79 | else |
| 80 | THIS_FILE="$0" |
| 81 | fi |
| 82 | cd "$(dirnamescip-shell system . . dirname. "$THIS_FILE")/.." |
| 83 | } |
| 84 | |
| 85 | exit_failurescip-shell shell shell-project 0.0.0 exit_failure().() { |
| 86 | exit 1 |
| 87 | } |
| 88 | |
| 89 | # Main |
| 90 | |
| 91 | if [scip-shell system . . `[`. $# -eq 1 ]; then |
| 92 | commit_before="$1~1" |
| 93 | commit_after="$1" |
| 94 | elif [scip-shell system . . `[`. $# -eq 2 ]; then |
| 95 | commit_before="$1" |
| 96 | commit_after="$2" |
| 97 | else |
| 98 | print_usagescip-shell shell shell-project 0.0.0 print_usage(). |
| 99 | exit_failurescip-shell shell shell-project 0.0.0 exit_failure(). |
| 100 | fi |
| 101 | |
| 102 | cd_to_rootscip-shell shell shell-project 0.0.0 cd_to_root(). |
| 103 | |
| 104 | printfscip-shell system . . printf. "Measuring commit %s..." "$commit_before" |
| 105 | preparescip-shell shell shell-project 0.0.0 prepare(). "$commit_before" |
| 106 | speed1=$(measure_speedscip-shell shell shell-project 0.0.0 measure_speed().) |
| 107 | size1=$(measure_sizescip-shell shell shell-project 0.0.0 measure_size().) |
| 108 | echoscip-shell system . . echo. " OK" |
| 109 | |
| 110 | printfscip-shell system . . printf. "Measuring commit %s..." "$commit_after" |
| 111 | preparescip-shell shell shell-project 0.0.0 prepare(). "$commit_after" |
| 112 | speed2=$(measure_speedscip-shell shell shell-project 0.0.0 measure_speed().) |
| 113 | size2=$(measure_sizescip-shell shell shell-project 0.0.0 measure_size().) |
| 114 | echoscip-shell system . . echo. " OK" |
| 115 | |
| 116 | print_resultsscip-shell shell shell-project 0.0.0 print_results(). $speed1 $speed2 $size1 $size2 |