Created
July 4, 2025 19:48
-
-
Save MohamedElashri/ea46fb9e67ac7ce75668f1acb28d126a to your computer and use it in GitHub Desktop.
Benchamrk new linux machines by compiling ROOT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # root_benchmark.sh – compile a minimal ROOT and collect build metrics | |
| set -euo pipefail | |
| ############### Color helpers ############### | |
| bold=$(tput bold) || true | |
| red=$(tput setaf 1) || true | |
| green=$(tput setaf 2) || true | |
| yellow=$(tput setaf 3) || true | |
| blue=$(tput setaf 4) || true | |
| reset=$(tput sgr0) || true | |
| info() { printf "%s➤ %s%s\n" "$blue" "$*" "$reset"; } | |
| warn() { printf "%s⚠ %s%s\n" "$yellow" "$*" "$reset"; } | |
| ok() { printf "%s✔ %s%s\n" "$green" "$*" "$reset"; } | |
| fail() { printf "%s✖ %s%s\n" "$red" "$*" "$reset"; exit 1; } | |
| ############### Pre-flight ############### | |
| [[ $EUID -eq 0 ]] || fail "Run as root or via sudo." | |
| cores_total=$(nproc --all) | |
| make_jobs=$(( cores_total > 1 ? cores_total-1 : 1 )) | |
| timestamp=$(date +%Y%m%d_%H%M%S) | |
| work_dir="/tmp/root-build-$timestamp" | |
| build_dir="$work_dir/build" | |
| install_dir="$work_dir/root-install" # never leaves /tmp; keeps CMake happy | |
| ############### Dependency handling ############### | |
| install_deps() { | |
| source /etc/os-release | |
| case ${ID_LIKE:-$ID} in | |
| *debian*) | |
| info "Detected Debian/Ubuntu family" | |
| apt-get update -qq | |
| apt-get install -y --no-install-recommends \ | |
| build-essential cmake git python3 \ | |
| gfortran libssl-dev libx11-dev libxext-dev libxi-dev;; | |
| *fedora*|*rhel*) | |
| info "Detected Fedora/RHEL family" | |
| dnf -y install gcc gcc-c++ gcc-gfortran cmake git \ | |
| openssl-devel libX11-devel libXext-devel libXi-devel python3;; | |
| *) | |
| fail "Unsupported distro – edit script to add dependencies.";; | |
| esac | |
| ok "Dependencies installed" | |
| } | |
| ############### ROOT build ############### | |
| build_root() { | |
| info "Cloning ROOT source (minimal)…" | |
| git clone --depth 1 https://github.com/root-project/root.git "$work_dir/root" | |
| mkdir -p "$build_dir" | |
| cd "$build_dir" | |
| info "Configuring CMake (minimal)…" | |
| cmake ../root \ | |
| -DCMAKE_INSTALL_PREFIX="$install_dir" \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -Dminimal=ON \ | |
| -Dx11=OFF \ | |
| -Droofit=OFF \ | |
| -Dhttp=OFF \ | |
| -Dpyroot=OFF \ | |
| -Dtmva=OFF \ | |
| > cmake.log 2>&1 | |
| info "Building with $make_jobs parallel job(s)…" | |
| build_start=$(date +%s) | |
| make -j"$make_jobs" > build.log 2>&1 | |
| build_end=$(date +%s) | |
| build_seconds=$(( build_end - build_start )) | |
| ok "Build completed in $build_seconds s" | |
| build_size_bytes=$(du -sb . | cut -f1) | |
| build_size_mb=$(( build_size_bytes / 1024 / 1024 )) | |
| } | |
| ############### Benchmark capture ############### | |
| capture_metrics() { | |
| info "Capturing hardware information…" | |
| cpu_model=$(lscpu | awk -F: '/Model name/{print $2; exit}' | sed 's/^[ \t]*//') | |
| mem_kb=$(grep MemTotal /proc/meminfo | awk '{print $2}') | |
| mem_gb=$(awk "BEGIN {printf \"%.1f\", $mem_kb/1024/1024}") | |
| results_file="$PWD/root-benchmark-$timestamp.txt" | |
| { | |
| printf "ROOT Build Benchmark – %s\n" "$(date)" | |
| printf "------------------------------------------------------------\n" | |
| printf "Hostname : %s\n" "$(hostname)" | |
| printf "CPU : %s\n" "$cpu_model" | |
| printf "Total cores : %s\n" "$cores_total" | |
| printf "Jobs used : %s\n" "$make_jobs" | |
| printf "Memory (GiB) : %s\n" "$mem_gb" | |
| printf "Build seconds : %s\n" "$build_seconds" | |
| printf "Build size MB : %s\n" "$build_size_mb" | |
| printf "------------------------------------------------------------\n\n" | |
| printf "| %-12s | %-35s | %5s | %4s | %6s | %7s | %6s |\n" \ | |
| "Host" "CPU" "Cores" "Jobs" "MemGB" "Time(s)" "SizeMB" | |
| printf "|--------------|-------------------------------------|-------|------|--------|---------|--------|\n" | |
| printf "| %-12s | %-35.35s | %5s | %4s | %6s | %7s | %6s |\n" \ | |
| "$(hostname | cut -c1-12)" \ | |
| "$cpu_model" \ | |
| "$cores_total" \ | |
| "$make_jobs" \ | |
| "$mem_gb" \ | |
| "$build_seconds" \ | |
| "$build_size_mb" | |
| } > "$results_file" | |
| ok "Results saved to $results_file" | |
| printf "\n%s" "$(cat "$results_file")" | |
| } | |
| ############### Cleanup ############### | |
| cleanup() { | |
| info "Removing build artefacts from /tmp…" | |
| rm -rf "$work_dir" | |
| ok "Cleanup done" | |
| } | |
| ############### Main flow ############### | |
| main() { | |
| install_deps | |
| build_root | |
| capture_metrics | |
| cleanup | |
| } | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment