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 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 diff --git a/benchmarks/run-benchmarks.sh b/benchmarks/run-benchmarks.sh new file mode 100755 index 0000000..225a60e --- /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 <(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 +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" 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 + ]; +}