pegjs/tools/impact
David Majda 9956b42392 Switch from Make to Gulp
The core of the transition is getting rid of Makefile and replacing it
with gulpfile.js. The rest is details (fixing dependencies, changing all
references to "make", etc.).

Target/task names mostly stay the same, so in most cases "gulp foo" does
what "make foo" did before. The only exceptions are "make browser" and
"make browserclean", which are now "gulp browser:build" and "gulp
browser:clean" (it feels more systematic).

Functionality is mostly unchanged (modulo Gulp clutter in the console),
but there are two small exceptions:

  gulp spec

    The reporter now displays just dots while previously it displayed
    spec descriptions. There is also a deprecation warning (most likely
    because I used an old version of gulp-jasmine in order to support
    Jasmine 1.x). I kept these issues unfixed because I plan to switch
    to Mocha soon (#409).

  gulp browser:build

    The copyright header is now added manually both to the development
    and minified build. Before, it was added only to the development
    build and the minified build relied on preserving it using "uglify
    --comments". This was broken since switching to //-style comments.

    There is now also an empty line between the header and the source
    code.

Fixes #444.
2016-10-11 11:53:25 +02:00

117 lines
2.1 KiB
Bash
Executable file

#!/bin/sh
# Measures impact of a Git commit (or multiple commits) on generated parsers'
# speed and size. Makes sense to use only on PEG.js Git repository checkout.
set -e
export LC_ALL=C
# Measurement
prepare() {
git checkout --quiet "$1"
}
run_benchmark() {
echo $(gulp benchmark | awk 'BEGIN { FS = " *│ *" } /Total/ { split($5, a, " "); print a[1] }')
}
measure_speed() {
bc <<-EOT
scale = 2
($(run_benchmark) + $(run_benchmark) + $(run_benchmark) + $(run_benchmark) + $(run_benchmark)) / 5
EOT
}
measure_size() {
for file in examples/*.pegjs; do
bin/pegjs "$file"
done
echo $(cat examples/*.js | wc -c)
rm examples/*.js
}
difference() {
bc <<-EOT
scale = 4
($2 / $1 - 1) * 100
EOT
}
# Helpers
print_results() {
echo
echo "Speed impact"
echo "------------"
echo "Before: $1 kB/s"
echo "After: $2 kB/s"
printf "Difference: %0.2f%%\n" $(difference $1 $2)
echo
echo "Size impact"
echo "-----------"
echo "Before: $3 b"
echo "After: $4 b"
printf "Difference: %0.2f%%\n" $(difference $3 $4)
echo
echo "(Measured by /tools/impact with Node.js $(node --version) on $(uname -mrs).)"
}
print_usage() {
echo "Usage:"
echo " $0 <commit>"
echo " $0 <commit_before> <commit_after>"
echo
echo "Measures impact of a Git commit (or multiple commits) on generated parsers'"
echo "speed and size. Makes sense to use only on PEG.js Git repository checkout."
}
cd_to_root() {
if [ -L "$0" ]; then
THIS_FILE=$(readlink "$0")
else
THIS_FILE="$0"
fi
cd "$(dirname "$THIS_FILE")/.."
}
exit_failure() {
exit 1
}
# Main
if [ $# -eq 1 ]; then
commit_before="$1~1"
commit_after="$1"
elif [ $# -eq 2 ]; then
commit_before="$1"
commit_after="$2"
else
print_usage
exit_failure
fi
cd_to_root
printf "Measuring commit %s..." "$commit_before"
prepare "$commit_before"
speed1=$(measure_speed)
size1=$(measure_size)
echo " OK"
printf "Measuring commit %s..." "$commit_after"
prepare "$commit_after"
speed2=$(measure_speed)
size2=$(measure_size)
echo " OK"
print_results $speed1 $speed2 $size1 $size2