minify-html/bench
Wilson Lin 82d287d9c4 Restructure Rust project 2021-08-08 17:40:42 +10:00
..
minify-html-bench Restructure Rust project 2021-08-08 17:40:42 +10:00
tests Fix ECMA-262 bench page 2020-08-24 23:59:19 +10:00
.gitignore Rename to minify-html 2020-07-12 01:29:34 +10:00
.nvmrc Fix handling of <script> and <style>; do not minify JS and CSS code 2020-01-10 00:12:21 +11:00
README.md 0.6.0 2021-08-08 13:01:44 +10:00
bench.sh Fix HTML_ONLY env not passed to bench 2020-07-25 16:13:56 +10:00
build.sh Restore Windows support; fix Node.js paths 2020-07-22 21:52:54 +10:00
compare.sh Use actual Node.js library name for bench; allow benchmarking without JS minification 2020-07-25 13:59:21 +10:00
fetch.js Remove extensions from bench test files 2020-01-15 23:01:06 +11:00
graph.js Improve graph size 2021-08-08 13:59:21 +10:00
minifiers.js Fix style attr minification 2021-08-08 00:56:24 +10:00
package.json Modernise bench 2021-08-07 20:53:28 +10:00
profile.sh Rename to minify-html 2020-07-12 01:29:34 +10:00
results.js Create combined graph 2021-08-07 23:58:38 +10:00
sizes.js Modernise bench 2021-08-07 20:53:28 +10:00
speeds.js Use esbuild for minifiers in bench 2020-07-24 18:24:28 +10:00
tests.js Minify SVG attributes; minor QoL improvements 2020-01-24 03:53:09 +13:00

README.md

Benchmarking

This folder contains scripts used to test the performance and effectiveness of minify-html, for guided optimisation and/or comparisons.

It also contains a set of common web pages as tests for benchmarking.

Comparison

The Node.js version of minify-html is tested against html-minfier and minimize in two dimensions:

  • Speed as operations per second.
  • Minified file size compared to the original.

Benchmark.js is used to determine speed. Each minifier is run against each file in the tests folder, which are HTML pages fetched from popular websites:

File name URL
Amazon https://www.amazon.com/
BBC https://www.bbc.co.uk/
Bootstrap https://getbootstrap.com/docs/3.4/css/
Bing https://www.bing.com/
Coding Horror https://blog.codinghorror.com/
ECMA-262 https://www.ecma-international.org/ecma-262/10.0/index.html
Google https://www.google.com/
Hacker News https://news.ycombinator.com/
NY Times https://www.nytimes.com/
Reddit https://www.reddit.com/
Stack Overflow https://www.stackoverflow.com/
Twitter https://twitter.com/
Wikipedia https://en.wikipedia.org/wiki/Soil

Note that these pages are already mostly minified.

For more information on how the tests are fetched, see fetch.js.

On this project's README, average graphs are shown. Graphs showing per-test results are shown below:

Chart showing speed of HTML minifiers per test Chart showing effectiveness of HTML minifiers per test

Since speed depends on the input, speed charts show performance relative to the Node.js minify-html as a percentage.

The settings used for each minifier can be found in minifiers.js. Some settings to note:

  • conservativeCollapse is enabled for html-minifier as otherwise some whitespace would be unsafely removed with side effects. minify-html can safely remove whitespace with context if configured properly.

Running

Make sure to install the dependencies listed in package.json by running npm i or yarn.

Run build.sh to build @minify-html/js with the local minify-html.

Run sizes.js to run each HTML minifier against each test and record the minified size results. This will also output the minified files in min if inspection of minified outputs is necessary. compare.sh is a useful script for viewing a character-by-character diff between the minified outputs of minify-html and html-minifier for a specific test. Pass the test's file name as the first argument.

Run speeds.js to benchmark the performance of each HTML minifier against each test and record the op/s results.

Run graph.js to render graphs from recorded speed and size results in the results folder.

minify-html-bench

The minify-html-bench folder contains a Rust executable subproject that runs the local minify-html on all tests for many iterations to calculate speed as operations per second.

This can be useful for profiling the core code or checking the performance of minify-html in other languages with native bindings.

It takes two arguments:

  • --tests: path to the folder containing tests to use as inputs.
  • --iterations: how many iterations to run per test.

The results will be written to stdout as a JSON object, where properties are the test file names and values are the operations per second.

Profiling minify-html can be done on Linux by using profile.sh, which uses perf. The generated report can be used using perf report.