name: Benchmark
on:
workflow_dispatch:
inputs:
runner:
description: "Runner label"
default: ubuntu-latest
reps:
description: "Repetitions per row (the best is reported)"
default: "3"
suite:
description: "compare (trg against zgrep and rg) or inflate-modes (--inflate A/B at three archive sizes)"
default: compare
env:
CARGO_TERM_COLOR: always
jobs:
bench:
runs-on: ${{ inputs.runner }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install the tools being compared
run: sudo apt-get update -q && sudo apt-get install -y -q pigz ripgrep
- name: Build
run: |
cargo build --release
cargo build --release --no-default-features --target-dir target/miniz
mkdir -p bin
cp target/release/trg bin/trg-ng
cp target/miniz/release/trg bin/trg-miniz
- name: Build the corpus
if: inputs.suite == 'compare'
run: |
mkdir -p synth
python3 bench/synth_logs.py synth
SRC=synth bench/build_corpus.sh /tmp/trgbench
- name: Compare
if: inputs.suite == 'compare'
run: |
{
echo "## $(uname -m), $(nproc) cores"
echo
echo '```'
lscpu | grep -E 'Model name|^CPU\(s\)|Thread|L2|L3' || true
echo "SIMD: $(grep -owE 'avx2|avx512f|avx512vl|pclmulqdq|asimd|pmull|crc32' /proc/cpuinfo | sort -u | tr '\n' ' ')"
echo "$(rg --version | head -n1), $(gzip --version | head -n1), $(pigz --version 2>&1)"
echo
REPS=${{ inputs.reps }} TRG=bin/trg-miniz TRG_NAME=miniz_oxide TRG_ZLIBNG=bin/trg-ng \
bench/compare.sh /tmp/trgbench/corpus
echo '```'
} | tee results.md
cat results.md >> "$GITHUB_STEP_SUMMARY"
- name: Inflate modes
if: inputs.suite == 'inflate-modes'
run: |
{
echo "## $(uname -m), $(nproc) cores: --inflate modes"
echo
echo '```'
lscpu | grep -E 'Model name' || true
for scale in 0.004 0.04 1; do
mkdir -p "synth-$scale"
python3 bench/synth_logs.py "synth-$scale" "$scale"
SRC="synth-$scale" bench/build_corpus.sh "/tmp/trgbench-$scale" > /dev/null
python3 bench/inflate_modes.py "/tmp/trgbench-$scale/corpus" bin/trg-ng ${{ inputs.reps }}
rm -rf "/tmp/trgbench-$scale"
done
echo '```'
} | tee results.md
cat results.md >> "$GITHUB_STEP_SUMMARY"
- uses: actions/upload-artifact@v4
with:
name: bench-${{ inputs.suite }}-${{ inputs.runner }}
path: results.md