github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/scripts/bench.sh (about)

     1  #!/bin/bash
     2  
     3  set -e
     4  
     5  run_test() {
     6    commit=$1
     7    results=$2
     8    echo "Running benches on: ${commit}"
     9  
    10    git checkout -q $commit
    11    if [[ -n ${post_checkout} ]]; then
    12      eval "${post_checkout}"
    13    fi
    14  
    15    test="BUCKET=${BUCKET} AIS_ENDPOINT=${AIS_ENDPOINT} go test ${verbose} -p 1 -parallel 4 -count ${count} -timeout 2h -run=NONE -bench=${bench_name} ${bench_dir}"
    16    if [[ -n ${verbose} ]]; then
    17      eval $test | tee -a $results
    18    else
    19      eval $test > $results
    20    fi
    21  }
    22  
    23  # ./bench.sh cmp [--old-commit OLD_COMMIT] [--dir DIRECTORY] [--bench BENCHMARK_NAME] [--post_checkout SCRIPT_NAME] [--verbose]
    24  bench::compare() {
    25    old_commit=HEAD^
    26  
    27    # For now only support current commit.
    28    new_commit="@{-1}"
    29    current_hash=$(git rev-parse HEAD)
    30  
    31    bench_dir="./..." # By default run in root directory.
    32    bench_name="."    # By default run all benchmarks.
    33    verbose=""
    34    count=1
    35    while (( "$#" )); do
    36      case "${1}" in
    37        --dir) bench_dir="$2/..."; shift; shift;;
    38        --bench) bench_name=$2; shift; shift;;
    39        --post-checkout) post_checkout=$2; shift; shift;;
    40        --verbose) verbose="-v"; shift;;
    41        --count) count=$2; shift; shift;;
    42        --old-commit) old_commit=$2; shift; shift;;
    43        *) echo "fatal: unknown argument '${1}'"; exit 1;;
    44      esac
    45    done
    46    old_results=$(mktemp)
    47    new_results=$(mktemp)
    48    run_test ${old_commit} ${old_results}
    49    run_test ${current_hash} ${new_results}
    50    benchcmp ${old_results} ${new_results}
    51    errs=$(grep -ae "^--- FAIL: Bench" ${old_results} ${new_results})
    52    perror $1 "${errs}"
    53  }
    54  
    55  case "${1}" in
    56    cmp) shift; bench::compare "${@}" ;;
    57    *) echo "fatal: unknown argument '${1}'"; exit 1;;
    58  esac