Allow comparison
This commit is contained in:
parent
b18201169f
commit
0bed19e5ed
|
@ -18,6 +18,6 @@ for r in *; do
|
||||||
done
|
done
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
|
|
||||||
popd >/dev/null
|
|
||||||
|
|
||||||
echo "All done!"
|
echo "All done!"
|
||||||
|
|
||||||
|
popd >/dev/null
|
||||||
|
|
|
@ -29,6 +29,6 @@ for r in *; do
|
||||||
done
|
done
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
|
|
||||||
popd >/dev/null
|
|
||||||
|
|
||||||
echo "All done!"
|
echo "All done!"
|
||||||
|
|
||||||
|
popd >/dev/null
|
||||||
|
|
|
@ -5,6 +5,7 @@ const path = require("path");
|
||||||
const iterations = parseInt(process.env.MHB_ITERATIONS, 10);
|
const iterations = parseInt(process.env.MHB_ITERATIONS, 10);
|
||||||
const inputDir = process.env.MHB_INPUT_DIR;
|
const inputDir = process.env.MHB_INPUT_DIR;
|
||||||
const htmlOnly = process.env.MHB_HTML_ONLY === "1";
|
const htmlOnly = process.env.MHB_HTML_ONLY === "1";
|
||||||
|
const outputDir = process.env.MHB_OUTPUT_DIR;
|
||||||
|
|
||||||
const minifyHtmlCfg = minifyHtml.createConfiguration({
|
const minifyHtmlCfg = minifyHtml.createConfiguration({
|
||||||
minify_css: !htmlOnly,
|
minify_css: !htmlOnly,
|
||||||
|
@ -13,12 +14,19 @@ const minifyHtmlCfg = minifyHtml.createConfiguration({
|
||||||
|
|
||||||
const results = fs.readdirSync(inputDir).map((name) => {
|
const results = fs.readdirSync(inputDir).map((name) => {
|
||||||
const src = fs.readFileSync(path.join(inputDir, name));
|
const src = fs.readFileSync(path.join(inputDir, name));
|
||||||
|
|
||||||
|
const out = minifyHtml.minify(src, minifyHtmlCfg);
|
||||||
|
const len = out.byteLength;
|
||||||
|
if (outputDir) {
|
||||||
|
fs.writeFileSync(path.join(outputDir, name), out);
|
||||||
|
}
|
||||||
|
|
||||||
const start = process.hrtime.bigint();
|
const start = process.hrtime.bigint();
|
||||||
let len;
|
|
||||||
for (let i = 0; i < iterations; i++) {
|
for (let i = 0; i < iterations; i++) {
|
||||||
len = minifyHtml.minify(src, minifyHtmlCfg).byteLength;
|
minifyHtml.minify(src, minifyHtmlCfg);
|
||||||
}
|
}
|
||||||
const elapsed = process.hrtime.bigint() - start;
|
const elapsed = process.hrtime.bigint() - start;
|
||||||
|
|
||||||
return [name, len, iterations, Number(elapsed) / 1_000_000_000];
|
return [name, len, iterations, Number(elapsed) / 1_000_000_000];
|
||||||
});
|
});
|
||||||
console.log(JSON.stringify(results));
|
console.log(JSON.stringify(results));
|
||||||
|
|
|
@ -5,5 +5,6 @@
|
||||||
- `MHB_ITERATIONS`: times to run each input.
|
- `MHB_ITERATIONS`: times to run each input.
|
||||||
- `MHB_INPUT_DIR`: path to directory containing inputs. Files should be read from this directory and used as the inputs.
|
- `MHB_INPUT_DIR`: path to directory containing inputs. Files should be read from this directory and used as the inputs.
|
||||||
- `MHB_HTML_ONLY`: if set to `1`, `minify_css` and `minify_js` should be disabled.
|
- `MHB_HTML_ONLY`: if set to `1`, `minify_css` and `minify_js` should be disabled.
|
||||||
- The output should be a JSON array of tuples, where each tuples contains the input name, output size, iterations, and execution time in seconds (as a floating point value).
|
- `MHB_OUTPUT_DIR`: if set, output minified HTML for each input in this folder.
|
||||||
|
- The output should be a JSON array of tuples, where each tuples contains the input name, output UTF-8 byte length, iterations, and execution time in seconds (as a floating point value).
|
||||||
- The execution time should be measured using high-precision monotonic system clocks where possible.
|
- The execution time should be measured using high-precision monotonic system clocks where possible.
|
||||||
|
|
|
@ -6,6 +6,7 @@ const path = require("path");
|
||||||
const iterations = parseInt(process.env.MHB_ITERATIONS, 10);
|
const iterations = parseInt(process.env.MHB_ITERATIONS, 10);
|
||||||
const inputDir = process.env.MHB_INPUT_DIR;
|
const inputDir = process.env.MHB_INPUT_DIR;
|
||||||
const htmlOnly = process.env.MHB_HTML_ONLY === "1";
|
const htmlOnly = process.env.MHB_HTML_ONLY === "1";
|
||||||
|
const outputDir = process.env.MHB_OUTPUT_DIR;
|
||||||
|
|
||||||
const esbuildCss = (code) =>
|
const esbuildCss = (code) =>
|
||||||
esbuild.transformSync(code, {
|
esbuild.transformSync(code, {
|
||||||
|
@ -47,12 +48,19 @@ const htmlMinifierCfg = {
|
||||||
|
|
||||||
const results = fs.readdirSync(inputDir).map((name) => {
|
const results = fs.readdirSync(inputDir).map((name) => {
|
||||||
const src = fs.readFileSync(path.join(inputDir, name), "utf8");
|
const src = fs.readFileSync(path.join(inputDir, name), "utf8");
|
||||||
|
|
||||||
|
const out = htmlMinifier.minify(src, htmlMinifierCfg);
|
||||||
|
const len = Buffer.from(out, "utf8").length;
|
||||||
|
if (outputDir) {
|
||||||
|
fs.writeFileSync(path.join(outputDir, name), out);
|
||||||
|
}
|
||||||
|
|
||||||
const start = process.hrtime.bigint();
|
const start = process.hrtime.bigint();
|
||||||
let len;
|
|
||||||
for (let i = 0; i < iterations; i++) {
|
for (let i = 0; i < iterations; i++) {
|
||||||
len = htmlMinifier.minify(src, htmlMinifierCfg).length;
|
htmlMinifier.minify(src, htmlMinifierCfg);
|
||||||
}
|
}
|
||||||
const elapsed = process.hrtime.bigint() - start;
|
const elapsed = process.hrtime.bigint() - start;
|
||||||
|
|
||||||
return [name, len, iterations, Number(elapsed) / 1_000_000_000];
|
return [name, len, iterations, Number(elapsed) / 1_000_000_000];
|
||||||
});
|
});
|
||||||
console.log(JSON.stringify(results));
|
console.log(JSON.stringify(results));
|
||||||
|
|
|
@ -14,8 +14,7 @@ fn main() {
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|v| v == "1")
|
.filter(|v| v == "1")
|
||||||
.is_some();
|
.is_some();
|
||||||
|
let output_dir = env::var("MHB_OUTPUT_DIR").ok();
|
||||||
let tests = fs::read_dir(input_dir).unwrap().map(|d| d.unwrap());
|
|
||||||
|
|
||||||
let mut results: Vec<(String, usize, usize, f64)> = Vec::new();
|
let mut results: Vec<(String, usize, usize, f64)> = Vec::new();
|
||||||
let cfg = Cfg {
|
let cfg = Cfg {
|
||||||
|
@ -23,21 +22,25 @@ fn main() {
|
||||||
minify_js: !html_only,
|
minify_js: !html_only,
|
||||||
};
|
};
|
||||||
|
|
||||||
for t in tests {
|
for t in fs::read_dir(input_dir).unwrap().map(|d| d.unwrap()) {
|
||||||
let source = fs::read(t.path()).unwrap();
|
let source = fs::read(t.path()).unwrap();
|
||||||
|
let input_name = t.file_name().into_string().unwrap();
|
||||||
|
|
||||||
|
let mut output = source.to_vec();
|
||||||
|
let len = in_place(&mut output, &cfg).expect("failed to minify");
|
||||||
|
output.truncate(len);
|
||||||
|
if let Some(output_dir) = &output_dir {
|
||||||
|
fs::write(format!("{}/{}", output_dir, input_name), output).unwrap();
|
||||||
|
};
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut len = 0;
|
|
||||||
for _ in 0..iterations {
|
for _ in 0..iterations {
|
||||||
let mut data = source.to_vec();
|
let mut data = source.to_vec();
|
||||||
len = in_place(&mut data, &cfg).expect("failed to minify");
|
let _ = in_place(&mut data, &cfg).expect("failed to minify");
|
||||||
}
|
}
|
||||||
let elapsed = start.elapsed().as_secs_f64();
|
let elapsed = start.elapsed().as_secs_f64();
|
||||||
results.push((
|
|
||||||
t.file_name().into_string().unwrap(),
|
results.push((input_name, len, iterations, elapsed));
|
||||||
len,
|
|
||||||
iterations,
|
|
||||||
elapsed,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
serde_json::to_writer(stdout(), &results).unwrap();
|
serde_json::to_writer(stdout(), &results).unwrap();
|
||||||
|
|
|
@ -14,8 +14,7 @@ fn main() {
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|v| v == "1")
|
.filter(|v| v == "1")
|
||||||
.is_some();
|
.is_some();
|
||||||
|
let output_dir = env::var("MHB_OUTPUT_DIR").ok();
|
||||||
let tests = fs::read_dir(input_dir).unwrap().map(|d| d.unwrap());
|
|
||||||
|
|
||||||
let mut results: Vec<(String, usize, usize, f64)> = Vec::new();
|
let mut results: Vec<(String, usize, usize, f64)> = Vec::new();
|
||||||
let mut cfg = Cfg::new();
|
let mut cfg = Cfg::new();
|
||||||
|
@ -24,20 +23,23 @@ fn main() {
|
||||||
cfg.minify_js = true;
|
cfg.minify_js = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
for t in tests {
|
for t in fs::read_dir(input_dir).unwrap().map(|d| d.unwrap()) {
|
||||||
let source = fs::read(t.path()).unwrap();
|
let source = fs::read(t.path()).unwrap();
|
||||||
|
let input_name = t.file_name().into_string().unwrap();
|
||||||
|
|
||||||
|
let output = minify(&source, &cfg);
|
||||||
|
let len = output.len();
|
||||||
|
if let Some(output_dir) = &output_dir {
|
||||||
|
fs::write(format!("{}/{}", output_dir, input_name), output).unwrap();
|
||||||
|
};
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut len = 0;
|
|
||||||
for _ in 0..iterations {
|
for _ in 0..iterations {
|
||||||
len = minify(&source, &cfg).len();
|
let _ = minify(&source, &cfg);
|
||||||
}
|
}
|
||||||
let elapsed = start.elapsed().as_secs_f64();
|
let elapsed = start.elapsed().as_secs_f64();
|
||||||
results.push((
|
|
||||||
t.file_name().into_string().unwrap(),
|
results.push((input_name, len, iterations, elapsed));
|
||||||
len,
|
|
||||||
iterations,
|
|
||||||
elapsed,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
serde_json::to_writer(stdout(), &results).unwrap();
|
serde_json::to_writer(stdout(), &results).unwrap();
|
||||||
|
|
|
@ -6,6 +6,7 @@ const path = require("path");
|
||||||
const iterations = parseInt(process.env.MHB_ITERATIONS, 10);
|
const iterations = parseInt(process.env.MHB_ITERATIONS, 10);
|
||||||
const inputDir = process.env.MHB_INPUT_DIR;
|
const inputDir = process.env.MHB_INPUT_DIR;
|
||||||
const htmlOnly = process.env.MHB_HTML_ONLY === "1";
|
const htmlOnly = process.env.MHB_HTML_ONLY === "1";
|
||||||
|
const outputDir = process.env.MHB_OUTPUT_DIR;
|
||||||
|
|
||||||
const jsMime = new Set([
|
const jsMime = new Set([
|
||||||
undefined,
|
undefined,
|
||||||
|
@ -58,14 +59,23 @@ const jsCssPlugin = {
|
||||||
|
|
||||||
const plugins = htmlOnly ? [] : [jsCssPlugin];
|
const plugins = htmlOnly ? [] : [jsCssPlugin];
|
||||||
|
|
||||||
|
const minifier = new minimize({ plugins });
|
||||||
|
|
||||||
const results = fs.readdirSync(inputDir).map((name) => {
|
const results = fs.readdirSync(inputDir).map((name) => {
|
||||||
const src = fs.readFileSync(path.join(inputDir, name), "utf8");
|
const src = fs.readFileSync(path.join(inputDir, name), "utf8");
|
||||||
|
|
||||||
|
const out = minifier.parse(src);
|
||||||
|
const len = Buffer.from(out, "utf8").length;
|
||||||
|
if (outputDir) {
|
||||||
|
fs.writeFileSync(path.join(outputDir, name), out);
|
||||||
|
}
|
||||||
|
|
||||||
const start = process.hrtime.bigint();
|
const start = process.hrtime.bigint();
|
||||||
let len;
|
|
||||||
for (let i = 0; i < iterations; i++) {
|
for (let i = 0; i < iterations; i++) {
|
||||||
len = new minimize({ plugins }).parse(src).length;
|
minifier.parse(src);
|
||||||
}
|
}
|
||||||
const elapsed = process.hrtime.bigint() - start;
|
const elapsed = process.hrtime.bigint() - start;
|
||||||
|
|
||||||
return [name, len, iterations, Number(elapsed) / 1_000_000_000];
|
return [name, len, iterations, Number(elapsed) / 1_000_000_000];
|
||||||
});
|
});
|
||||||
console.log(JSON.stringify(results));
|
console.log(JSON.stringify(results));
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
/outputs/
|
|
@ -1 +1 @@
|
||||||
[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.
|
[compare](./compare) is a useful script for viewing a character-by-character diff between the minified outputs of minify-html and html-minifier for a specific input. Pass the input's file name as the first argument.
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -Eeuxo pipefail
|
||||||
|
|
||||||
|
pushd "$(dirname "$0")" >/dev/null
|
||||||
|
|
||||||
|
git --no-pager diff --no-index --word-diff=color --word-diff-regex=. "outputs/html-minifier/$1" "outputs/minify-html/$1" | less
|
||||||
|
|
||||||
|
popd >/dev/null
|
|
@ -1,3 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
git --no-pager diff --no-index --word-diff=color --word-diff-regex=. "min/html-minifier/$1.html" "min/@minify-html/js/$1.html" | less
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
|
pushd "$(dirname "$0")" >/dev/null
|
||||||
|
|
||||||
|
input_dir="$PWD/../../bench/inputs"
|
||||||
|
output_dir="$PWD/outputs"
|
||||||
|
|
||||||
|
rm -rf "$output_dir"
|
||||||
|
mkdir -p "$output_dir"
|
||||||
|
|
||||||
|
pushd "../../bench/runners" >/dev/null
|
||||||
|
for r in *; do
|
||||||
|
if [ ! -d "$r" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
mkdir -p "$output_dir/$r"
|
||||||
|
echo "Running $r..."
|
||||||
|
pushd "$r" >/dev/null
|
||||||
|
MHB_ITERATIONS=1 MHB_INPUT_DIR="$input_dir" MHB_OUTPUT_DIR="$output_dir/$r" RUST_BACKTRACE=1 ./run >/dev/null
|
||||||
|
popd >/dev/null
|
||||||
|
done
|
||||||
|
popd >/dev/null
|
||||||
|
|
||||||
|
echo "All done!"
|
||||||
|
|
||||||
|
popd >/dev/null
|
Loading…
Reference in New Issue