diff --git a/tests/compare/README.md b/tests/compare/README.md new file mode 100644 index 0000000..938d46f --- /dev/null +++ b/tests/compare/README.md @@ -0,0 +1,23 @@ +# Brotli Compare +Basic scripts to test any file comparing Gzip and Brotli across speed and compression strength. Output is dumped to an HTML result and plotted with Google Charts. It can be easily extended or changed to compare other compression engines. Note that default Brotli compression level (MAX) is not tested as it skews the graph for time but it's worth considering manually. + +## Usage +``` +$ git clone +$ ./test.sh [test file] +``` + +For best results clone into /tmp or tmpfs to guarantee eliminating I/O time. +Beware that each run will delete the results from a previous run in pwd, so best to work in a new directory with copies of files. + +## Viewing results +A local file will be generated called $INPUTFILE.results.html. This may be viewed with a browser: + +``` +$ xdg-open *results.html +``` + +The charts plot two data units on the same graph which is a no-no but it's nice to view both on one. + +## Example +![alt text](sample.png "Snapshot of example chart isn't interactive") diff --git a/tests/compare/compare.sh b/tests/compare/compare.sh new file mode 100755 index 0000000..c1f0a84 --- /dev/null +++ b/tests/compare/compare.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# John Boero - boeroboy@gmail.com +# v1.0 - SEP/2018 +# A Q&D one-filer to generate a comparison graph of gzip and broli performance and compression levels. +# Use this on any of your samples to determine your application's best option for compression engine and level. +# If using with a web server note that this script only gauges compression time and not network/app time or I/O. +# Run time may vary slightly based on background processes but compressed size is algo deterministic. +# Beware generated files are cleaned up but results are not. Always work with a copy in tmpfs. + +# USAGE: +# ./compare.sh samplefile.html + +# Gives microseconds for a task. +function microsecs() +{ + ts=$(date +%s%N) + $@ + tt=$((($(date +%s%N) - $ts)/1000)) + echo $tt +} + +if [[ ! -f $1 ]] +then + echo "Need to pass file arg." + exit 1 +fi + +rm -f *.br *.gz + +origsize=$(stat -c '%s' "$1") + +for level in {1..9} +do + brtime=$(microsecs brotli -$level -f -o "$1.$level.br" "$1") + brsize="$(stat -c '%s' ""$1.$level.br"")" + echo "brotli -$level: ${brtime}ms, ${brsize}b" + + gztime=$(microsecs gzip -$level -f -k "$1") + gzsize="$(stat -c '%s' ""$1.gz"")" + echo "gzip -$level: ${gztime}ms, ${gzsize}b" + rm -f "$1.gz" + + dataset="$dataset [$level, $gzsize, $brsize, $gztime, $brtime], " +done + +#rm -f *.br *.gz + +cat << EOF > "$1.results.html" + +Brotli performance chart for $1 original size $origsize bytes. + + +

Brotli performance chart for $1 original size $origsize bytes.

+
+ + +EOF diff --git a/tests/compare/sample.png b/tests/compare/sample.png new file mode 100644 index 0000000..c04c156 Binary files /dev/null and b/tests/compare/sample.png differ