From 2912a753e3ead51e56e6132389b0cd0f4c5b370b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20M=2E=20Bezerra?= Date: Wed, 23 Nov 2022 02:26:11 -0300 Subject: [PATCH 1/5] create scripts for benchmarking ouch --- benchmarks/run-benchmarks.sh | 117 +++++++++++++++++++++++++++++++++ benchmarks/setup-benchmarks.sh | 39 +++++++++++ 2 files changed, 156 insertions(+) create mode 100755 benchmarks/run-benchmarks.sh create mode 100755 benchmarks/setup-benchmarks.sh diff --git a/benchmarks/run-benchmarks.sh b/benchmarks/run-benchmarks.sh new file mode 100755 index 0000000..7538641 --- /dev/null +++ b/benchmarks/run-benchmarks.sh @@ -0,0 +1,117 @@ +#!/usr/bin/env bash +# +# Input files used: +# - `compiler` (27 MB) for compressed formats. +# - `rust` (229 MB) for uncompressed formats. +# +# Compressed formats benchmarked: +# - .tar.gz +# - .zip +# +# Uncompressed formats benchmarked: +# - .tar + +set -e + +DESCOMPRESSION_CLEANUP="rm output -r" + +function call_hyperfine() { + hyperfine "$@" \ + --warmup 4 \ + --export-markdown "${FUNCNAME[1]}.md" +} + +function tar_compression() { + cleanup="rm output.tar" + + call_hyperfine \ + 'ouch compress rust output.tar' \ + 'tar -cvf output.tar rust' \ + --prepare "$cleanup || true" + + $cleanup +} + +function tar_decompression() { + echo "Creating tar archive to benchmark decompression..." + ouch compress rust input.tar --yes &> /dev/null + + call_hyperfine \ + 'ouch decompress input.tar --dir output' \ + 'tar -xv -C output -f input.tar' \ + --prepare "$DESCOMPRESSION_CLEANUP || true" \ + --prepare "$DESCOMPRESSION_CLEANUP || true ; mkdir output" + + $DESCOMPRESSION_CLEANUP +} + +function tar_gz_compression() { + cleanup="rm output.tar.gz" + + call_hyperfine \ + 'ouch compress compiler output.tar.gz' \ + 'tar -cvzf output.tar.gz compiler' \ + --prepare "$cleanup || true" + + $cleanup +} + +function tar_gz_decompression() { + echo "Creating tar.gz archive to benchmark decompression..." + ouch compress compiler input.tar.gz --yes &> /dev/null + + call_hyperfine \ + 'ouch decompress input.tar.gz --dir output' \ + 'tar -xvz -C output -f input.tar.gz' \ + --prepare "$DESCOMPRESSION_CLEANUP || true" \ + --prepare "$DESCOMPRESSION_CLEANUP || true ; mkdir output" + + $DESCOMPRESSION_CLEANUP +} + +function zip_compression() { + cleanup="rm output.zip" + + call_hyperfine \ + 'zip output.zip -r compiler' \ + 'ouch compress compiler output.zip' \ + --prepare "$cleanup || true" + + $cleanup +} + +function zip_decompression() { + echo "Creating zip archive to benchmark decompression..." + ouch compress compiler input.zip --yes &> /dev/null + + call_hyperfine \ + 'ouch decompress input.zip --dir output' \ + 'unzip input.zip -d output' \ + --prepare "$DESCOMPRESSION_CLEANUP || true" + + $DESCOMPRESSION_CLEANUP +} + +function run_benches() { + tar_compression + tar_decompression + tar_gz_compression + tar_gz_decompression + zip_compression + zip_decompression +} + +function concatenate_results() { + cat tar_compression.md > results.md ; echo "" >> results.md + cat tar_decompression.md >> results.md ; echo "" >> results.md + cat tar_gz_compression.md >> results.md ; echo "" >> results.md + cat tar_gz_decompression.md >> results.md ; echo "" >> results.md + cat zip_compression.md >> results.md ; echo "" >> results.md + cat zip_decompression.md >> results.md +} + +run_benches +concatenate_results + +echo +echo "check results at results.md" diff --git a/benchmarks/setup-benchmarks.sh b/benchmarks/setup-benchmarks.sh new file mode 100755 index 0000000..ced6f3f --- /dev/null +++ b/benchmarks/setup-benchmarks.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Run this script inside of the folder `benchmarks` to download +# the input files to run the benchmarks. +# +# ``` +# cd benchmarks +# ./setup-benchmarks.sh +# ``` +# +# It will download rust-lang's source code. +# +# After this, you can run `./run-benchmarks.sh`. +# +# Input files downloaded: +# - `compiler` (27 MB) for compressed formats. +# - `rust` (229 MB) for uncompressed formats. + +set -e + +function setup() { + if [[ -d "rust" || -d "compiler" ]]; then + echo "Input files already exist, try deleting before downloading again." + exit 1 + fi + + # Download the Rust 1.65.0 source code + git clone -b 1.65.0 https://github.com/rust-lang/rust --depth 1 + + # Delete write-protected files to make benchmark cleanup simpler + rm rust/.git -fr + + # Separate the compiler code + cp rust/compiler -r compiler +} + +setup + +echo "tip: if you see a git warning above, you can ignore it" From e80a7ea8c5b785ed083554446eef13a9297db9ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20M=2E=20Bezerra?= Date: Wed, 23 Nov 2022 02:32:17 -0300 Subject: [PATCH 2/5] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85af6a5..c9832d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,6 +106,7 @@ Categories Used: - Show subcommand aliases on --help [\#275](https://github.com/ouch-org/ouch/pull/275) ([marcospb19](https://github.com/marcospb19)) - Update dependencies [\#276](https://github.com/ouch-org/ouch/pull/276) ([figsoda](https://github.com/figsoda)) - Rewrite progress module [\#280](https://github.com/ouch-org/ouch/pull/280) ([figsoda](https://github.com/figsoda)) +- Create scripts for benchmarking ouch [\#280](https://github.com/ouch-org/ouch/pull/280) ([figsoda](https://github.com/figsoda)) ### Regression From b49fad7b96bf8f752aa41f046ba31cdd494f5816 Mon Sep 17 00:00:00 2001 From: figsoda Date: Wed, 23 Nov 2022 10:16:57 -0500 Subject: [PATCH 3/5] add files generated by benchmarks to gitignore --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index f2bf630..b5355c7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,10 @@ target/ # Common folder for generated shell completions and man pages artifacts/ + +# extra files generated by benchmarks +/benchmarks/compiler/ +/benchmarks/rust/ +/benchmarks/input.* +/benchmarks/*.md +!/benchmarks/results.md From 56c91078df976675f224990ae252356f278a9049 Mon Sep 17 00:00:00 2001 From: figsoda Date: Wed, 23 Nov 2022 10:17:23 -0500 Subject: [PATCH 4/5] simplify concatenating benchmark results --- benchmarks/run-benchmarks.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/benchmarks/run-benchmarks.sh b/benchmarks/run-benchmarks.sh index 7538641..225a60e 100755 --- a/benchmarks/run-benchmarks.sh +++ b/benchmarks/run-benchmarks.sh @@ -102,12 +102,12 @@ function run_benches() { } function concatenate_results() { - cat tar_compression.md > results.md ; echo "" >> results.md - cat tar_decompression.md >> results.md ; echo "" >> results.md - cat tar_gz_compression.md >> results.md ; echo "" >> results.md - cat tar_gz_decompression.md >> results.md ; echo "" >> results.md - cat zip_compression.md >> results.md ; echo "" >> results.md - cat zip_decompression.md >> results.md + cat tar_compression.md <(echo) \ + tar_decompression.md <(echo) \ + tar_gz_compression.md <(echo) \ + tar_gz_decompression.md <(echo) \ + zip_compression.md <(echo) \ + zip_decompression.md > results.md } run_benches From 3ad029d46fc39a337557243ea6eee704bb7f22d6 Mon Sep 17 00:00:00 2001 From: figsoda Date: Wed, 23 Nov 2022 10:17:40 -0500 Subject: [PATCH 5/5] add shell.nix for benchmarks --- benchmarks/shell.nix | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 benchmarks/shell.nix diff --git a/benchmarks/shell.nix b/benchmarks/shell.nix new file mode 100644 index 0000000..f7f37ae --- /dev/null +++ b/benchmarks/shell.nix @@ -0,0 +1,22 @@ +{ pkgs ? import { } }: + +with pkgs; + +let + ouch = rustPlatform.buildRustPackage { + pname = "ouch"; + inherit ((lib.importTOML ../Cargo.toml).package) version; + src = ../.; + cargoLock.lockFile = ../Cargo.lock; + }; +in + +mkShell { + packages = [ + gnutar + hyperfine + ouch + unzip + zip + ]; +}