mirror of
https://github.com/google/brotli.git
synced 2024-11-22 03:30:07 +00:00
Added compare tool dir.
This commit is contained in:
parent
6eba239a5b
commit
a85627bf01
23
tests/compare/README.md
Normal file
23
tests/compare/README.md
Normal file
@ -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")
|
113
tests/compare/compare.sh
Executable file
113
tests/compare/compare.sh
Executable file
@ -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"
|
||||
<html>
|
||||
<title>Brotli performance chart for $1 original size $origsize bytes.</title>
|
||||
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
google.charts.load('current', {packages: ['corechart', 'line']});
|
||||
google.charts.setOnLoadCallback(drawAxisTickColors);
|
||||
|
||||
function drawAxisTickColors() {
|
||||
var data = new google.visualization.DataTable();
|
||||
data.addColumn('number', 'X');
|
||||
data.addColumn('number', 'GZIP Size (bytes)');
|
||||
data.addColumn('number', 'Brotli Size (bytes)');
|
||||
data.addColumn('number', 'GZIP Time (microsec)');
|
||||
data.addColumn('number', 'Brotli Time (microsec)');
|
||||
|
||||
data.addRows([
|
||||
$dataset
|
||||
]);
|
||||
|
||||
var options = {
|
||||
'title':'Brotli vs Gzip time and size',
|
||||
'width':1440,
|
||||
'height':1024,
|
||||
hAxis: {
|
||||
title: 'Compression Level',
|
||||
textStyle: {
|
||||
color: '#01579b',
|
||||
fontSize: 20,
|
||||
fontName: 'Arial',
|
||||
bold: true,
|
||||
italic: true
|
||||
},
|
||||
titleTextStyle: {
|
||||
color: '#01579b',
|
||||
fontSize: 16,
|
||||
fontName: 'Arial',
|
||||
bold: false,
|
||||
italic: true
|
||||
}
|
||||
},
|
||||
vAxis: {
|
||||
title: 'Time/Size',
|
||||
textStyle: {
|
||||
color: '#1a237e',
|
||||
fontSize: 24,
|
||||
bold: true
|
||||
},
|
||||
titleTextStyle: {
|
||||
color: '#1a237e',
|
||||
fontSize: 24,
|
||||
bold: true
|
||||
}
|
||||
},
|
||||
colors: ['#FF0000', '#00FF00', '#FF00FF', '#0000FF']
|
||||
};
|
||||
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
|
||||
chart.draw(data, options);
|
||||
}
|
||||
</script>
|
||||
<body><h1>Brotli performance chart for $1 original size $origsize bytes.</h1>
|
||||
<div id="chart_div"></div>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
BIN
tests/compare/sample.png
Normal file
BIN
tests/compare/sample.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 57 KiB |
Loading…
Reference in New Issue
Block a user