diff --git a/bench/bench.sh b/bench/bench.sh index 8d9b527..09b9024 100755 --- a/bench/bench.sh +++ b/bench/bench.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -set -e +set -Eeuo pipefail + shopt -s nullglob for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do @@ -9,12 +10,19 @@ done results_dir="$PWD/results" input_dir="$PWD/inputs" -iterations=100 +iterations=1 -pushd runners +pushd runners >/dev/null for r in *; do - pushd "$r" - ./build - sudo --preserve-env=MHB_HTML_ONLY,PATH MHB_ITERATIONS=$iterations MHB_INPUT_DIR="$input_dir" nice -n -20 taskset -c 1 ./run | tee "$results_dir/$r.json" - popd + if [ ! -d "$r" ]; then + continue + fi + echo "Running $r..." + pushd "$r" >/dev/null + out="$results_dir/$r.json" + sudo --preserve-env=MHB_HTML_ONLY,PATH MHB_ITERATIONS=$iterations MHB_INPUT_DIR="$input_dir" nice -n -20 taskset -c 1 ./run > "$out" + popd >/dev/null done +popd >/dev/null + +echo "All done!" diff --git a/bench/build.sh b/bench/build.sh new file mode 100644 index 0000000..c7ab5a7 --- /dev/null +++ b/bench/build.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +shopt -s nullglob + +pushd runners >/dev/null +for r in *; do + if [ ! -d "$r" ]; then + continue + fi + echo "Building $r..." + pushd "$r" >/dev/null + ./build + popd >/dev/null +done +popd >/dev/null + +echo "All done!" diff --git a/bench/runners/html-minifier/index.js b/bench/runners/html-minifier/index.js index e3f2a55..8fa2be3 100644 --- a/bench/runners/html-minifier/index.js +++ b/bench/runners/html-minifier/index.js @@ -7,6 +7,18 @@ const iterations = parseInt(process.env.MHB_ITERATIONS, 10); const inputDir = process.env.MHB_INPUT_DIR; const htmlOnly = process.env.MHB_HTML_ONLY === "1"; +const esbuildCss = (code) => + esbuild.transformSync(code, { + loader: "css", + minify: true, + }).code; + +const esbuildJs = (code) => + esbuild.transformSync(code, { + loader: "js", + minify: true, + }).code; + const htmlMinifierCfg = { collapseBooleanAttributes: true, collapseInlineTagWhitespace: true, @@ -33,18 +45,6 @@ const htmlMinifierCfg = { useShortDoctype: true, }; -const esbuildCss = (code) => - esbuild.transformSync(code, { - loader: "css", - minify: true, - }).code; - -const esbuildJs = (code) => - esbuild.transformSync(code, { - loader: "js", - minify: true, - }).code; - const results = fs.readdirSync(inputDir).map((name) => { const src = fs.readFileSync(path.join(inputDir, name), "utf8"); const start = process.hrtime.bigint(); diff --git a/bench/runners/minify-html (Rust)/run b/bench/runners/minify-html (Rust)/run index 820dfb2..f80876e 100755 --- a/bench/runners/minify-html (Rust)/run +++ b/bench/runners/minify-html (Rust)/run @@ -2,4 +2,4 @@ set -Eeuxo pipefail -cargo run --release +./target/release/minify-html-bench diff --git a/bench/runners/minify-html (Rust)/src/main.rs b/bench/runners/minify-html (Rust)/src/main.rs index 14980b3..565b993 100644 --- a/bench/runners/minify-html (Rust)/src/main.rs +++ b/bench/runners/minify-html (Rust)/src/main.rs @@ -22,8 +22,7 @@ fn main() { let source = fs::read(t.path()).unwrap(); let start = Instant::now(); for _ in 0..iterations { - let data = source.to_vec(); - minify(&source, &cfg); + let _ = minify(&source, &cfg); }; let elapsed = start.elapsed().as_secs_f64(); results.push((t.file_name().into_string().unwrap(), elapsed)); diff --git a/bench/runners/minify-html-onepass (Rust)/run b/bench/runners/minify-html-onepass (Rust)/run index 820dfb2..78dadb1 100755 --- a/bench/runners/minify-html-onepass (Rust)/run +++ b/bench/runners/minify-html-onepass (Rust)/run @@ -2,4 +2,4 @@ set -Eeuxo pipefail -cargo run --release +./target/release/minify-html-onepass-bench diff --git a/bench/runners/minify-html-onepass (Rust)/src/main.rs b/bench/runners/minify-html-onepass (Rust)/src/main.rs index 071d639..868db67 100644 --- a/bench/runners/minify-html-onepass (Rust)/src/main.rs +++ b/bench/runners/minify-html-onepass (Rust)/src/main.rs @@ -12,7 +12,7 @@ fn main() { let tests = fs::read_dir(input_dir).unwrap().map(|d| d.unwrap()); let mut results: Vec<(String, f64)> = Vec::new(); - let mut cfg = Cfg { + let cfg = Cfg { minify_css: !html_only, minify_js: !html_only, }; @@ -22,7 +22,7 @@ fn main() { let start = Instant::now(); for _ in 0..iterations { let mut data = source.to_vec(); - let _ = in_place(&mut data, &cfg).unwrap(); + let _ = in_place(&mut data, &cfg).expect("failed to minify"); }; let elapsed = start.elapsed().as_secs_f64(); results.push((t.file_name().into_string().unwrap(), elapsed));