#!/bin/bash # Benchmark script to compare cargo test vs cargo nextest # Usage: ./benchmark_nextest.sh set -e PACKAGE="common" TEST_FILTER="test_" echo "================================" echo "Cargo Test vs Nextest Benchmark" echo "================================" echo "Package: $PACKAGE" echo "Test filter: $TEST_FILTER" echo "" # Clean build to ensure fair comparison echo "[1/5] Cleaning build artifacts..." cargo clean -p $PACKAGE echo "" # Build with regular cargo test echo "[2/5] Building with 'cargo test' (no run)..." start_time=$(date +%s.%N) cargo test --package $PACKAGE --lib --no-run 2>&1 | tail -3 end_time=$(date +%s.%N) cargo_test_build_time=$(echo "$end_time - $start_time" | bc) echo "Cargo test build time: ${cargo_test_build_time}s" echo "" # Run with regular cargo test echo "[3/5] Running tests with 'cargo test'..." start_time=$(date +%s.%N) cargo test --package $PACKAGE --lib $TEST_FILTER 2>&1 | tail -5 end_time=$(date +%s.%N) cargo_test_run_time=$(echo "$end_time - $start_time" | bc) echo "Cargo test run time: ${cargo_test_run_time}s" echo "" # Clean again for nextest echo "[4/5] Cleaning for nextest comparison..." cargo clean -p $PACKAGE echo "" # Build and run with nextest echo "[5/5] Building and running with 'cargo nextest'..." start_time=$(date +%s.%N) cargo nextest run --package $PACKAGE --lib $TEST_FILTER 2>&1 | tail -10 end_time=$(date +%s.%N) nextest_total_time=$(echo "$end_time - $start_time" | bc) echo "Nextest total time (build + run): ${nextest_total_time}s" echo "" # Summary echo "================================" echo "SUMMARY" echo "================================" echo "cargo test:" echo " - Build time: ${cargo_test_build_time}s" echo " - Run time: ${cargo_test_run_time}s" echo " - Total: $(echo "$cargo_test_build_time + $cargo_test_run_time" | bc)s" echo "" echo "cargo nextest:" echo " - Total time: ${nextest_total_time}s" echo "" cargo_total=$(echo "$cargo_test_build_time + $cargo_test_run_time" | bc) speedup=$(echo "scale=2; $cargo_total / $nextest_total_time" | bc) if (( $(echo "$speedup > 1" | bc -l) )); then echo "✅ nextest is ${speedup}x faster!" elif (( $(echo "$speedup < 1" | bc -l) )); then slowdown=$(echo "scale=2; $nextest_total_time / $cargo_total" | bc) echo "⚠️ nextest is ${slowdown}x slower" else echo "⚡ Performance is equivalent" fi echo ""