Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active September 23, 2026 16:48
Show Gist options
  • Select an option

  • Save amirrajan/0732e675346fca3ab4e7f19c01ad8806 to your computer and use it in GitHub Desktop.

Select an option

Save amirrajan/0732e675346fca3ab4e7f19c01ad8806 to your computer and use it in GitHub Desktop.
java build benchmark thingy
#!/usr/bin/env bash
# git clone https://gist.github.com/amirrajan/0732e675346fca3ab4e7f19c01ad8806 benchmark-java-build && cd ./benchmark-java-build && sh ./go.sh
# Clone Kafka 4.0.2, fetch the benchmark script, and run it.
set -eu
git clone --depth 1 --branch 4.0.2 https://github.com/apache/kafka.git
cd kafka
cp ../kafka-bench.sh ./kafka-bench.sh
bash ./kafka-bench.sh 1
#!/usr/bin/env bash
# Kafka machine benchmark: two independent categories, each fully isolated
# (own warm-up, own clean before every timed run).
#
# build : compile main + test (Java + Scala) + checkstyle + spotbugs
# io : distribution packaging -- jars, dependency copies, tar + gzip
# (timer includes the compile that releaseTarGz depends on)
#
# Usage: ./bench-build.sh [runs] (default 3)
set -u
RUNS="${1:-3}"
GRADLE="--no-build-cache --console=plain --no-scan"
RESULTS=""
BUILD_TASKS="testClasses checkstyleMain checkstyleTest spotbugsMain"
IO_TASKS=":core:releaseTarGz"
echo "=== environment ==="
uname -a
java -version 2>&1
./gradlew --version | sed -n '3,12p'
echo "cores: $(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc)"
echo
# run_category <name> <tasks...>
run_category() {
name="$1"; shift
tasks="$*"
# warm up: download deps, start + JIT-warm the daemon, fill page cache
echo "=== [$name] warm up (not timed) ==="
./gradlew $GRADLE $tasks || { echo "[$name] warm-up FAILED"; exit 1; }
echo
for i in $(seq 1 "$RUNS"); do
echo "=== [$name] timed run $i/$RUNS ==="
./gradlew $GRADLE clean >/dev/null || { echo "[$name] clean FAILED"; exit 1; }
start=$(date +%s)
./gradlew $GRADLE --rerun-tasks $tasks >/dev/null || { echo "[$name] run $i FAILED"; exit 1; }
end=$(date +%s)
RESULTS="${RESULTS}${name} run ${i}: $((end - start))s"$'\n'
done
echo
}
run_category build $BUILD_TASKS
run_category io $IO_TASKS
echo "=== summary (--no-build-cache --rerun-tasks, $RUNS runs each) ==="
echo " build : $BUILD_TASKS"
echo " io : $IO_TASKS (includes dependent compile)"
echo
printf '%s' "$RESULTS"
echo
printf '%s' "$RESULTS" | awk '{gsub(/s$/,"",$4); c=$1; t[c]+=$4; n[c]++; if(m[c]==""||$4<m[c])m[c]=$4}
END{for(c in t) printf "%-6s best: %ds mean: %.1fs n=%d\n", c, m[c], t[c]/n[c], n[c]}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment