minify-html/bench
Wilson Lin 996a531147 0.2.4 2020-07-11 23:26:37 +10:00
..
hyperbuild-bench Set up Go for workflows; fix args in more places 2020-07-11 01:33:38 +10:00
tests Remove extensions from bench test files 2020-01-15 23:01:06 +11:00
.gitignore Improve bench infra 2020-01-26 21:23:23 +13: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.2.4 2020-07-11 23:26:37 +10:00
bench.sh Improve performance through inlining and direct arrays 2020-01-31 23:15:35 +11:00
build.sh Use local version for unpublished Cargo projects 2020-07-11 23:25:36 +10:00
compare.sh Remove attrs with default values; create minified comparison script; remove `=` from boolean attrs; fix closing tag writing before collapsed whitespace; rebuild hyperbuild only in bench build script instead of all dependencies; conservatively collapse whitespace for html-minifier to match hyperbuild behaviour; update bench results 2020-01-18 11:42:01 +11:00
fetch.js Remove extensions from bench test files 2020-01-15 23:01:06 +11:00
graph.js Fix op/s typos 2020-01-25 03:08:00 +13:00
minifiers.js Fix missing arg to hyperbuild-nodejs in bench 2020-07-11 01:39:48 +10:00
package.json Update html-minifier in bench 2020-01-26 17:09:19 +13:00
profile.sh Improve performance through inlining and direct arrays 2020-01-31 23:15:35 +11:00
results.js Benchmark with workflow instead 2020-01-26 16:38:14 +13:00
sizes.js Improve bench infra 2020-01-26 21:23:23 +13:00
speeds.js Improve bench infra 2020-01-26 21:23:23 +13: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 hyperbuild, 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 hyperbuild 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 hyperbuild-nodejs as a percentage.

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

  • JS and CSS minification is disabled for all, as hyperbuild is an HTML minifier and there are existing separate tools for such tasks.
  • conservativeCollapse is enabled for html-minifier as otherwise some whitespace would be unsafely removed with side affects. hyperbuild 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. Node.js 10 is required, and system dependencies for building canvas, used for rendering graphs, may need to be installed. See the npm package for more details.

Run build.sh to build hyperbuild-nodejs with the local hyperbuild.

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 hyperbuild 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.

hyperbuild-bench

The hyperbuild-bench folder contains a Rust executable subproject that runs the local hyperbuild 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 hyperbuild 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 hyperbuild can be done on Linux by using profile.sh, which uses perf. The generated report can be used using perf report.