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] 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"