minify-html/bench/README.md

72 lines
3.8 KiB
Markdown
Raw Normal View History

2020-01-24 09:04:07 -05:00
# Benchmarking
2020-07-11 11:29:34 -04:00
This folder contains scripts used to test the performance and effectiveness of minify-html, for guided optimisation and/or comparisons.
2020-01-24 09:04:07 -05:00
2020-01-25 22:38:14 -05:00
It also contains a set of common web pages as tests for benchmarking.
2020-01-24 09:04:07 -05:00
## Comparison
2020-07-11 11:29:34 -04:00
The [Node.js version of minify-html](../nodejs) is tested against [html-minfier](https://github.com/kangax/html-minifier) and [minimize](https://github.com/Swaagie/minimize) in two dimensions:
2020-01-24 09:04:07 -05:00
- Speed as operations per second.
- Minified file size compared to the original.
[Benchmark.js](https://benchmarkjs.com) is used to determine speed. Each minifier is run against each file in the [tests](./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/|
2020-01-24 09:06:04 -05:00
|ECMA-262|https://www.ecma-international.org/ecma-262/10.0/index.html|
2020-01-24 09:04:07 -05:00
|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.**
2020-01-24 09:04:07 -05:00
For more information on how the tests are fetched, see [fetch.js](./fetch.js).
2020-01-26 03:23:23 -05:00
On this [project's README](../README.md), average graphs are shown. Graphs showing per-test results are shown below:
2020-01-24 09:04:07 -05:00
2021-08-09 04:11:57 -04:00
<img width="435" alt="Chart showing speed of HTML minifiers per test" src="https://wilsonl.in/minify-html/bench/0.6.1/core/speeds.png"> <img width="435" alt="Chart showing effectiveness of HTML minifiers per test" src="https://wilsonl.in/minify-html/bench/0.6.1/core/sizes.png">
2020-01-24 09:04:07 -05:00
2020-07-11 11:29:34 -04:00
Since speed depends on the input, speed charts show performance relative to the Node.js minify-html as a percentage.
2020-01-24 09:04:07 -05:00
The settings used for each minifier can be found in [minifiers.js](./minifiers.js). Some settings to note:
2021-01-07 02:10:24 -05:00
- `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.
2020-01-24 09:04:07 -05:00
## Running
2021-08-07 06:53:28 -04:00
Make sure to install the dependencies listed in [package.json](./package.json) by running `npm i` or `yarn`.
2020-01-24 09:04:07 -05:00
Run [build.sh](./build.sh) to build @minify-html/js with the local minify-html.
2020-01-24 09:04:07 -05:00
2020-07-11 11:29:34 -04:00
Run [sizes.js](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](./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.
2020-01-24 09:04:07 -05:00
2020-01-26 03:23:23 -05:00
Run [speeds.js](./speeds.js) to benchmark the performance of each HTML minifier against each test and record the op/s results.
2020-01-24 09:04:07 -05:00
Run [graph.js](./graph.js) to render graphs from recorded speed and size results in the `results` folder.
2020-01-24 09:04:07 -05:00
2020-07-11 11:29:34 -04:00
## minify-html-bench
2020-01-24 09:04:07 -05:00
2020-07-11 11:29:34 -04:00
The [minify-html-bench](./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.
2020-01-24 09:04:07 -05:00
2020-07-11 11:29:34 -04:00
This can be useful for profiling the core code or checking the performance of minify-html in other languages with native bindings.
2020-01-24 09:04:07 -05:00
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.
2020-07-11 11:29:34 -04:00
Profiling minify-html can be done on Linux by using [profile.sh](./profile.sh), which uses `perf`. The generated report can be used using `perf report`.