Merge pull request #6235 from libgit2/ethomson/cli_benchmarks Benchmarking suite
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml
new file mode 100644
index 0000000..7ae14ca
--- /dev/null
+++ b/.github/workflows/benchmark.yml
@@ -0,0 +1,78 @@
+# Benchmark libgit2 against the git reference implementation.
+name: Benchmark
+
+on:
+ workflow_dispatch:
+ schedule:
+ - cron: '15 4 * * *'
+
+jobs:
+ # Run our nightly builds. We build a matrix with the various build
+ # targets and their details. Then we build either in a docker container
+ # (Linux) or on the actual hosts (macOS, Windows).
+ build:
+ strategy:
+ matrix:
+ platform:
+ - name: "Linux (clang, OpenSSL)"
+ env:
+ CC: clang
+ CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release
+ CMAKE_BUILD_OPTIONS: --config Release
+ id: linux
+ os: ubuntu-latest
+ setup-script: ubuntu
+ - name: "macOS"
+ os: macos-10.15
+ env:
+ CC: clang
+ CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release
+ CMAKE_BUILD_OPTIONS: --config Release
+ PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
+ id: macos
+ setup-script: osx
+ - name: "Windows (amd64, Visual Studio)"
+ os: windows-2019
+ env:
+ ARCH: amd64
+ CMAKE_GENERATOR: Visual Studio 16 2019
+ CMAKE_OPTIONS: -A x64 -DDEPRECATE_HARD=ON -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release
+ CMAKE_BUILD_OPTIONS: --config Release
+ id: windows
+ setup-script: win32
+ fail-fast: false
+ name: "Build ${{ matrix.platform.name }}"
+ env: ${{ matrix.platform.env }}
+ runs-on: ${{ matrix.platform.os }}
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v2
+ with:
+ path: source
+ fetch-depth: 0
+ - name: Set up benchmark environment
+ run: source/ci/setup-${{ matrix.platform.setup-script }}-benchmark.sh
+ shell: bash
+ if: matrix.platform.setup-script != ''
+ - name: Build
+ run: |
+ mkdir build && cd build
+ ../source/ci/build.sh
+ shell: bash
+ - name: Benchmark
+ run: |
+ if [[ "$(uname -s)" == MINGW* ]]; then
+ GIT2_CLI="$(cygpath -w $(pwd))\\build\\Release\\git2_cli"
+ else
+ GIT2_CLI="$(pwd)/build/git2_cli"
+ fi
+
+ mkdir benchmark && cd benchmark
+ ../source/tests/benchmarks/benchmark.sh --baseline-cli "git" --cli "${GIT2_CLI}" --json benchmarks.json --zip benchmarks.zip
+ shell: bash
+ - name: Upload results
+ uses: actions/upload-artifact@v2
+ with:
+ name: benchmark-${{ matrix.platform.id }}
+ path: benchmark
+ if: always()
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 74bab53..0ac8b8b 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -214,7 +214,7 @@ jobs:
path: source
fetch-depth: 0
- name: Set up build environment
- run: source/ci/setup-${{ matrix.platform.setup-script }}.sh
+ run: source/ci/setup-${{ matrix.platform.setup-script }}-build.sh
shell: bash
if: matrix.platform.setup-script != ''
- name: Setup QEMU
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index 5513d5b..4f24be6 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -271,7 +271,7 @@ jobs:
path: source
fetch-depth: 0
- name: Set up build environment
- run: source/ci/setup-${{ matrix.platform.setup-script }}.sh
+ run: source/ci/setup-${{ matrix.platform.setup-script }}-build.sh
shell: bash
if: matrix.platform.setup-script != ''
- name: Setup QEMU
diff --git a/ci/build.sh b/ci/build.sh
index 5a51f92..21a45af 100755
--- a/ci/build.sh
+++ b/ci/build.sh
@@ -59,7 +59,7 @@ echo "##########################################################################
echo "## Configuring build environment"
echo "##############################################################################"
-echo cmake -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G \"${CMAKE_GENERATOR}\" ${CMAKE_OPTIONS} -S \"${SOURCE_DIR}\"
+echo "${CMAKE}" -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G \"${CMAKE_GENERATOR}\" ${CMAKE_OPTIONS} -S \"${SOURCE_DIR}\"
env PATH="${BUILD_PATH}" "${CMAKE}" -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G "${CMAKE_GENERATOR}" ${CMAKE_OPTIONS} -S "${SOURCE_DIR}"
echo ""
@@ -69,10 +69,11 @@ echo "##########################################################################
# Determine parallelism; newer cmake supports `--build --parallel` but
# we cannot yet rely on that.
-if [ "${CMAKE_GENERATOR}" = "Unix Makefiles" -a "${CORES}" != "" ]; then
+if [ "${CMAKE_GENERATOR}" = "Unix Makefiles" -a "${CORES}" != "" -a "${CMAKE_BUILD_OPTIONS}" = "" ]; then
BUILDER=(make -j ${CORES})
else
- BUILDER=("${CMAKE}" --build .)
+ BUILDER=("${CMAKE}" --build . ${CMAKE_BUILD_OPTIONS})
fi
+echo "${BUILDER[@]}"
env PATH="${BUILD_PATH}" "${BUILDER[@]}"
diff --git a/ci/setup-mingw-build.sh b/ci/setup-mingw-build.sh
new file mode 100755
index 0000000..3d72b24
--- /dev/null
+++ b/ci/setup-mingw-build.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -ex
+
+echo "##############################################################################"
+echo "## Downloading mingw"
+echo "##############################################################################"
+
+BUILD_TEMP=${BUILD_TEMP:=$TEMP}
+BUILD_TEMP=$(cygpath $BUILD_TEMP)
+
+case "$ARCH" in
+ amd64)
+ MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2021-05-04/mingw-x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";;
+ x86)
+ MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2021-05-04/mingw-i686-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";;
+esac
+
+if [ -z "$MINGW_URI" ]; then
+ echo "No URL"
+ exit 1
+fi
+
+mkdir -p "$BUILD_TEMP"
+
+curl -s -L "$MINGW_URI" -o "$BUILD_TEMP"/mingw-"$ARCH".zip
+unzip -q "$BUILD_TEMP"/mingw-"$ARCH".zip -d "$BUILD_TEMP"
diff --git a/ci/setup-mingw.sh b/ci/setup-mingw.sh
deleted file mode 100755
index f5a882d..0000000
--- a/ci/setup-mingw.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/sh -e
-
-echo "##############################################################################"
-echo "## Downloading mingw"
-echo "##############################################################################"
-
-BUILD_TEMP=${BUILD_TEMP:=$TEMP}
-BUILD_TEMP=$(cygpath $BUILD_TEMP)
-
-case "$ARCH" in
- amd64)
- MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2021-05-04/mingw-x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";;
- x86)
- MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2021-05-04/mingw-i686-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";;
-esac
-
-if [ -z "$MINGW_URI" ]; then
- echo "No URL"
- exit 1
-fi
-
-mkdir -p "$BUILD_TEMP"
-
-curl -s -L "$MINGW_URI" -o "$BUILD_TEMP"/mingw-"$ARCH".zip
-unzip -q "$BUILD_TEMP"/mingw-"$ARCH".zip -d "$BUILD_TEMP"
diff --git a/ci/setup-osx-benchmark.sh b/ci/setup-osx-benchmark.sh
new file mode 100755
index 0000000..80d8768
--- /dev/null
+++ b/ci/setup-osx-benchmark.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+set -ex
+
+brew update
+brew install hyperfine
diff --git a/ci/setup-osx-build.sh b/ci/setup-osx-build.sh
new file mode 100755
index 0000000..0b95e76
--- /dev/null
+++ b/ci/setup-osx-build.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+set -ex
+
+brew update
+brew install pkgconfig zlib curl openssl libssh2 ninja
+
+ln -s /Applications/Xcode.app/Contents/Developer/usr/lib/libLeaksAtExit.dylib /usr/local/lib
diff --git a/ci/setup-osx.sh b/ci/setup-osx.sh
deleted file mode 100755
index 2e630ee..0000000
--- a/ci/setup-osx.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-set -x
-
-brew update
-brew install pkgconfig zlib curl openssl libssh2 ninja
-
-ln -s /Applications/Xcode.app/Contents/Developer/usr/lib/libLeaksAtExit.dylib /usr/local/lib
diff --git a/ci/setup-ubuntu-benchmark.sh b/ci/setup-ubuntu-benchmark.sh
new file mode 100755
index 0000000..561a18f
--- /dev/null
+++ b/ci/setup-ubuntu-benchmark.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+set -ex
+
+sudo apt-get update
+sudo apt-get install -y --no-install-recommends \
+ cargo \
+ cmake \
+ gcc \
+ git \
+ krb5-user \
+ libkrb5-dev \
+ libssl-dev \
+ libz-dev \
+ make \
+ ninja-build \
+ pkgconf
+
+wget https://github.com/sharkdp/hyperfine/releases/download/v1.12.0/hyperfine_1.12.0_amd64.deb
+sudo dpkg -i hyperfine_1.12.0_amd64.deb
diff --git a/ci/setup-win32-benchmark.sh b/ci/setup-win32-benchmark.sh
new file mode 100755
index 0000000..0eac2f6
--- /dev/null
+++ b/ci/setup-win32-benchmark.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+set -ex
+
+choco install hyperfine zip
+
+CHOCO_PATH=$(mktemp -d)
+curl -L https://github.com/ethomson/PurgeStandbyList/releases/download/v1.0/purgestandbylist.1.0.0.nupkg -o "${CHOCO_PATH}/purgestandbylist.1.0.0.nupkg"
+choco install purgestandbylist -s $(cygpath -w "${CHOCO_PATH}")
diff --git a/tests/README.md b/tests/README.md
index 5920b15..460e045 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -2,6 +2,8 @@
These are the unit and integration tests for the libgit2 projects.
+* `benchmarks`
+ These are benchmark tests that excercise the CLI.
* `clar`
This is [clar](https://github.com/clar-test/clar) the common test framework.
* `headertest`
diff --git a/tests/benchmarks/README.md b/tests/benchmarks/README.md
new file mode 100644
index 0000000..f66b27a
--- /dev/null
+++ b/tests/benchmarks/README.md
@@ -0,0 +1,121 @@
+# libgit2 benchmarks
+
+This folder contains the individual benchmark tests for libgit2,
+meant for understanding the performance characteristics of libgit2,
+comparing your development code to the existing libgit2 code, or
+comparing libgit2 to the git reference implementation.
+
+## Running benchmark tests
+
+Benchmark tests can be run in several different ways: running all
+benchmarks, running one (or more) suite of benchmarks, or running a
+single individual benchmark. You can target either an individual
+version of a CLI, or you can A/B test a baseline CLI against a test
+CLI.
+
+### Specifying the command-line interface to test
+
+By default, the `git` in your path is benchmarked. Use the
+`-c` (or `--cli`) option to specify the command-line interface
+to test.
+
+Example: `libgit2_bench --cli git2_cli` will run the tests against
+`git2_cli`.
+
+### Running tests to compare two different implementations
+
+You can compare a baseline command-line interface against a test
+command-line interface using the `-b (or `--baseline-cli`) option.
+
+Example: `libgit2_bench --baseline-cli git --cli git2_cli` will
+run the tests against both `git` and `git2_cli`.
+
+### Running individual benchmark tests
+
+Similar to how a test suite or individual test is specified in
+[clar](https://github.com/clar-test/clar), the `-s` (or `--suite`)
+option may be used to specify the suite or individual test to run.
+Like clar, the suite and test name are separated by `::`, and like
+clar, this is a prefix match.
+
+Examples:
+* `libgit2_bench -shash_object` will run the tests in the
+ `hash_object` suite.
+* `libgit2_bench -shash_object::random_1kb` will run the
+ `hash_object::random_1kb` test.
+* `libgit2_bench -shash_object::random` will run all the tests that
+ begin with `hash_object::random`.
+
+## Writing benchmark tests
+
+Benchmark tests are meant to be easy to write. Each individual
+benchmark is a shell script that allows it to do set up (eg, creating
+or cloning a repository, creating temporary files, etc), then running
+benchmarks, then teardown.
+
+The `benchmark_helpers.sh` script provides many helpful utility
+functions to allow for cross-platform benchmarking, as well as a
+wrapper for `hyperfine` that is suited to testing libgit2.
+Note that the helper script must be included first, at the beginning
+of the benchmark test.
+
+### Benchmark example
+
+This simplistic example compares the speed of running the `git help`
+command in the baseline CLI to the test CLI.
+
+```bash
+#!/bin/bash -e
+
+# include the benchmark library
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+# run the "help" command; this will benchmark `git2_cli help`
+gitbench help
+```
+
+### Naming
+
+The filename of the benchmark itself is important. A benchmark's
+filename should be the name of the benchmark suite, followed by two
+underscores, followed by the name of the benchmark. For example,
+`hash-object__random_1kb` is the `random_1kb` test in the `hash-object`
+suite.
+
+### Options
+
+The `gitbench` function accepts several options.
+
+* `--sandbox <path>`
+ The name of a test resource (in the `tests/resources` directory).
+ This will be copied as-is to the sandbox location before test
+ execution. This is copied _before_ the `prepare` script is run.
+ This option may be specified multiple times.
+* `--repository <path>`
+ The name of a test resource repository (in the `tests/resources`
+ directory). This repository will be copied into a sandbox location
+ before test execution, and your test will run in this directory.
+ This is copied _before_ the `prepare` script is run.
+* `--prepare <script>`
+ A script to run before each invocation of the test is run. This can
+ set up data for the test that will _not_ be timed. This script is run
+ in bash on all platforms.
+
+ Several helper functions are available within the context of a prepare
+ script:
+
+ * `flush_disk_cache`
+ Calling this will flush the disk cache before each test run.
+ This should probably be run at the end of the `prepare` script.
+ * `create_random_file <path> [<size>]`
+ Calling this will populate a file at the given `path` with `size`
+ bytes of random data.
+ * `create_text_file <path> [<size>]`
+ Calling this will populate a file at the given `path` with `size`
+ bytes of predictable text, with the platform line endings. This
+ is preferred over random data as it's reproducible.
+
+* `--warmup <n>`
+ Specifies that the test should run `n` times before actually measuring
+ the timing; useful for "warming up" a cache.
+
diff --git a/tests/benchmarks/benchmark.sh b/tests/benchmarks/benchmark.sh
new file mode 100755
index 0000000..4a89807
--- /dev/null
+++ b/tests/benchmarks/benchmark.sh
@@ -0,0 +1,298 @@
+#!/bin/bash
+
+set -eo pipefail
+
+#
+# parse the command line
+#
+
+usage() { echo "usage: $(basename "$0") [--cli <path>] [--baseline-cli <path>] [--suite <suite>] [--json <path>] [--zip <path>] [--verbose] [--debug]"; }
+
+TEST_CLI="git"
+BASELINE_CLI=
+SUITE=
+JSON_RESULT=
+ZIP_RESULT=
+OUTPUT_DIR=
+VERBOSE=
+DEBUG=
+NEXT=
+
+for a in "$@"; do
+ if [ "${NEXT}" = "cli" ]; then
+ TEST_CLI="${a}"
+ NEXT=
+ elif [ "${NEXT}" = "baseline-cli" ]; then
+ BASELINE_CLI="${a}"
+ NEXT=
+ elif [ "${NEXT}" = "suite" ]; then
+ SUITE="${a}"
+ NEXT=
+ elif [ "${NEXT}" = "json" ]; then
+ JSON_RESULT="${a}"
+ NEXT=
+ elif [ "${NEXT}" = "zip" ]; then
+ ZIP_RESULT="${a}"
+ NEXT=
+ elif [ "${NEXT}" = "output-dir" ]; then
+ OUTPUT_DIR="${a}"
+ NEXT=
+ elif [ "${a}" = "c" ] || [ "${a}" = "--cli" ]; then
+ NEXT="cli"
+ elif [[ "${a}" == "-c"* ]]; then
+ TEST_CLI="${a/-c/}"
+ elif [ "${a}" = "b" ] || [ "${a}" = "--baseline-cli" ]; then
+ NEXT="baseline-cli"
+ elif [[ "${a}" == "-b"* ]]; then
+ BASELINE_CLI="${a/-b/}"
+ elif [ "${a}" = "-s" ] || [ "${a}" = "--suite" ]; then
+ NEXT="suite"
+ elif [[ "${a}" == "-s"* ]]; then
+ SUITE="${a/-s/}"
+ elif [ "${a}" = "-v" ] || [ "${a}" == "--verbose" ]; then
+ VERBOSE=1
+ elif [ "${a}" == "--debug" ]; then
+ VERBOSE=1
+ DEBUG=1
+ elif [ "${a}" = "-j" ] || [ "${a}" == "--json" ]; then
+ NEXT="json"
+ elif [[ "${a}" == "-j"* ]]; then
+ JSON_RESULT="${a/-j/}"
+ elif [ "${a}" = "-z" ] || [ "${a}" == "--zip" ]; then
+ NEXT="zip"
+ elif [[ "${a}" == "-z"* ]]; then
+ ZIP_RESULT="${a/-z/}"
+ elif [ "${a}" = "--output-dir" ]; then
+ NEXT="output-dir"
+ else
+ echo "$(basename "$0"): unknown option: ${a}" 1>&2
+ usage 1>&2
+ exit 1
+ fi
+done
+
+if [ "${NEXT}" != "" ]; then
+ usage 1>&2
+ exit 1
+fi
+
+if [ "${OUTPUT_DIR}" = "" ]; then
+ OUTPUT_DIR=${OUTPUT_DIR:="$(mktemp -d)"}
+ CLEANUP_DIR=1
+fi
+
+#
+# collect some information about the test environment
+#
+
+SYSTEM_OS=$(uname -s)
+if [ "${SYSTEM_OS}" = "Darwin" ]; then SYSTEM_OS="macOS"; fi
+
+SYSTEM_KERNEL=$(uname -v)
+
+fullpath() {
+ if [[ "$(uname -s)" == "MINGW"* && $(cygpath -u "${TEST_CLI}") == "/"* ]]; then
+ echo "${TEST_CLI}"
+ elif [[ "${TEST_CLI}" == "/"* ]]; then
+ echo "${TEST_CLI}"
+ else
+ which "${TEST_CLI}"
+ fi
+}
+
+cli_version() {
+ if [[ "$(uname -s)" == "MINGW"* ]]; then
+ $(cygpath -u "$1") --version
+ else
+ "$1" --version
+ fi
+}
+
+TEST_CLI_NAME=$(basename "${TEST_CLI}")
+TEST_CLI_PATH=$(fullpath "${TEST_CLI}")
+TEST_CLI_VERSION=$(cli_version "${TEST_CLI}")
+
+if [ "${BASELINE_CLI}" != "" ]; then
+ if [[ "${BASELINE_CLI}" == "/"* ]]; then
+ BASELINE_CLI_PATH="${BASELINE_CLI}"
+ else
+ BASELINE_CLI_PATH=$(which "${BASELINE_CLI}")
+ fi
+
+ BASELINE_CLI_NAME=$(basename "${BASELINE_CLI}")
+ BASELINE_CLI_PATH=$(fullpath "${BASELINE_CLI}")
+ BASELINE_CLI_VERSION=$(cli_version "${BASELINE_CLI}")
+fi
+
+#
+# run the benchmarks
+#
+
+echo "##############################################################################"
+if [ "${SUITE}" != "" ]; then
+ SUITE_PREFIX="${SUITE/::/__}"
+ echo "## Running ${SUITE} benchmarks"
+else
+ echo "## Running all benchmarks"
+fi
+echo "##############################################################################"
+echo ""
+
+if [ "${BASELINE_CLI}" != "" ]; then
+ echo "# Baseline CLI: ${BASELINE_CLI} (${BASELINE_CLI_VERSION})"
+fi
+echo "# Test CLI: ${TEST_CLI} (${TEST_CLI_VERSION})"
+echo ""
+
+BENCHMARK_DIR=${BENCHMARK_DIR:=$(dirname "$0")}
+ANY_FOUND=
+ANY_FAILED=
+
+indent() { sed "s/^/ /"; }
+time_in_ms() { if [ "$(uname -s)" = "Darwin" ]; then date "+%s000"; else date "+%s%N" ; fi; }
+humanize_secs() {
+ units=('s' 'ms' 'us' 'ns')
+ unit=0
+ time="${1}"
+
+ if [ "${time}" = "" ]; then
+ echo ""
+ return
+ fi
+
+ # bash doesn't do floating point arithmetic. ick.
+ while [[ "${time}" == "0."* ]] && [ "$((unit+1))" != "${#units[*]}" ]; do
+ time="$(echo | awk "{ print ${time} * 1000 }")"
+ unit=$((unit+1))
+ done
+
+ echo "${time} ${units[$unit]}"
+}
+
+TIME_START=$(time_in_ms)
+
+for TEST_PATH in "${BENCHMARK_DIR}"/*; do
+ TEST_FILE=$(basename "${TEST_PATH}")
+
+ if [ ! -f "${TEST_PATH}" ] || [ ! -x "${TEST_PATH}" ]; then
+ continue
+ fi
+
+ if [[ "${TEST_FILE}" != *"__"* ]]; then
+ continue
+ fi
+
+ if [[ "${TEST_FILE}" != "${SUITE_PREFIX}"* ]]; then
+ continue
+ fi
+
+ ANY_FOUND=1
+ TEST_NAME="${TEST_FILE/__/::}"
+
+ echo -n "${TEST_NAME}:"
+ if [ "${VERBOSE}" = "1" ]; then
+ echo ""
+ else
+ echo -n " "
+ fi
+
+ if [ "${DEBUG}" = "1" ]; then
+ SHOW_OUTPUT="--show-output"
+ fi
+
+ OUTPUT_FILE="${OUTPUT_DIR}/${TEST_FILE}.out"
+ JSON_FILE="${OUTPUT_DIR}/${TEST_FILE}.json"
+ ERROR_FILE="${OUTPUT_DIR}/${TEST_FILE}.err"
+
+ FAILED=
+ ${TEST_PATH} --cli "${TEST_CLI}" --baseline-cli "${BASELINE_CLI}" --json "${JSON_FILE}" ${SHOW_OUTPUT} >"${OUTPUT_FILE}" 2>"${ERROR_FILE}" || FAILED=1
+
+ if [ "${FAILED}" = "1" ]; then
+ if [ "${VERBOSE}" != "1" ]; then
+ echo "failed!"
+ fi
+
+ indent < "${ERROR_FILE}"
+ ANY_FAILED=1
+ continue
+ fi
+
+ # in verbose mode, just print the hyperfine results; otherwise,
+ # pull the useful information out of its json and summarize it
+ if [ "${VERBOSE}" = "1" ]; then
+ indent < "${OUTPUT_FILE}"
+ else
+ jq -r '[ .results[0].mean, .results[0].stddev, .results[1].mean, .results[1].stddev ] | @tsv' < "${JSON_FILE}" | while IFS=$'\t' read -r one_mean one_stddev two_mean two_stddev; do
+ one_mean=$(humanize_secs "${one_mean}")
+ one_stddev=$(humanize_secs "${one_stddev}")
+
+ if [ "${two_mean}" != "" ]; then
+ two_mean=$(humanize_secs "${two_mean}")
+ two_stddev=$(humanize_secs "${two_stddev}")
+
+ echo "${one_mean} ± ${one_stddev} vs ${two_mean} ± ${two_stddev}"
+ else
+ echo "${one_mean} ± ${one_stddev}"
+ fi
+ done
+ fi
+
+ # add our metadata to the hyperfine json result
+ jq ". |= { \"name\": \"${TEST_NAME}\" } + ." < "${JSON_FILE}" > "${JSON_FILE}.new" && mv "${JSON_FILE}.new" "${JSON_FILE}"
+done
+
+TIME_END=$(time_in_ms)
+
+if [ "$ANY_FOUND" != "1" ]; then
+ echo ""
+ echo "error: no benchmark suite \"${SUITE}\"."
+ echo ""
+ exit 1
+fi
+
+escape() {
+ echo "${1//\\/\\\\}"
+}
+
+# combine all the individual benchmark results into a single json file
+if [ "${JSON_RESULT}" != "" ]; then
+ if [ "${VERBOSE}" = "1" ]; then
+ echo ""
+ echo "# Writing JSON results: ${JSON_RESULT}"
+ fi
+
+ SYSTEM_JSON="{ \"os\": \"${SYSTEM_OS}\", \"kernel\": \"${SYSTEM_KERNEL}\" }"
+ TIME_JSON="{ \"start\": ${TIME_START}, \"end\": ${TIME_END} }"
+ TEST_CLI_JSON="{ \"name\": \"${TEST_CLI_NAME}\", \"path\": \"$(escape "${TEST_CLI_PATH}")\", \"version\": \"${TEST_CLI_VERSION}\" }"
+ BASELINE_CLI_JSON="{ \"name\": \"${BASELINE_CLI_NAME}\", \"path\": \"$(escape "${BASELINE_CLI_PATH}")\", \"version\": \"${BASELINE_CLI_VERSION}\" }"
+
+ if [ "${BASELINE_CLI}" != "" ]; then
+ EXECUTOR_JSON="{ \"baseline\": ${BASELINE_CLI_JSON}, \"cli\": ${TEST_CLI_JSON} }"
+ else
+ EXECUTOR_JSON="{ \"cli\": ${TEST_CLI_JSON} }"
+ fi
+
+ # add our metadata to all the test results
+ jq -n "{ \"system\": ${SYSTEM_JSON}, \"time\": ${TIME_JSON}, \"executor\": ${EXECUTOR_JSON}, \"tests\": [inputs] }" "${OUTPUT_DIR}"/*.json > "${JSON_RESULT}"
+fi
+
+# combine all the data into a zip if requested
+if [ "${ZIP_RESULT}" != "" ]; then
+ if [ "${VERBOSE}" = "1" ]; then
+ if [ "${JSON_RESULT}" = "" ]; then echo ""; fi
+ echo "# Writing ZIP results: ${ZIP_RESULT}"
+ fi
+
+ zip -jr "${ZIP_RESULT}" "${OUTPUT_DIR}" >/dev/null
+fi
+
+if [ "$CLEANUP_DIR" = "1" ]; then
+ rm -f "${OUTPUT_DIR}"/*.out
+ rm -f "${OUTPUT_DIR}"/*.err
+ rm -f "${OUTPUT_DIR}"/*.json
+ rmdir "${OUTPUT_DIR}"
+fi
+
+if [ "$ANY_FAILED" = "1" ]; then
+ exit 1
+fi
diff --git a/tests/benchmarks/benchmark_helpers.sh b/tests/benchmarks/benchmark_helpers.sh
new file mode 100644
index 0000000..14dbb43
--- /dev/null
+++ b/tests/benchmarks/benchmark_helpers.sh
@@ -0,0 +1,363 @@
+# variables that benchmark tests can set
+#
+
+set -eo pipefail
+
+#
+# command-line parsing
+#
+
+usage() { echo "usage: $(basename "$0") [--cli <path>] [--baseline-cli <path>] [--output-style <style>] [--json <path>]"; }
+
+NEXT=
+BASELINE_CLI=
+TEST_CLI="git"
+JSON=
+SHOW_OUTPUT=
+
+if [ "$CI" != "" ]; then
+ OUTPUT_STYLE="color"
+else
+ OUTPUT_STYLE="auto"
+fi
+
+#
+# parse the arguments to the outer script that's including us; these are arguments that
+# the `benchmark.sh` passes (or that a user could specify when running an individual test)
+#
+
+for a in "$@"; do
+ if [ "${NEXT}" = "cli" ]; then
+ TEST_CLI="${a}"
+ NEXT=
+ elif [ "${NEXT}" = "baseline-cli" ]; then
+ BASELINE_CLI="${a}"
+ NEXT=
+ elif [ "${NEXT}" = "output-style" ]; then
+ OUTPUT_STYLE="${a}"
+ NEXT=
+ elif [ "${NEXT}" = "json" ]; then
+ JSON="${a}"
+ NEXT=
+ elif [ "${a}" = "-c" ] || [ "${a}" = "--cli" ]; then
+ NEXT="cli"
+ elif [[ "${a}" == "-c"* ]]; then
+ TEST_CLI="${a/-c/}"
+ elif [ "${a}" = "-b" ] || [ "${a}" = "--baseline-cli" ]; then
+ NEXT="baseline-cli"
+ elif [[ "${a}" == "-b"* ]]; then
+ BASELINE_CLI="${a/-b/}"
+ elif [ "${a}" == "--output-style" ]; then
+ NEXT="output-style"
+ elif [ "${a}" = "-j" ] || [ "${a}" = "--json" ]; then
+ NEXT="json"
+ elif [[ "${a}" == "-j"* ]]; then
+ JSON="${a}"
+ elif [ "${a}" = "--show-output" ]; then
+ SHOW_OUTPUT=1
+ OUTPUT_STYLE=
+ else
+ echo "$(basename "$0"): unknown option: ${a}" 1>&2
+ usage 1>&2
+ exit 1
+ fi
+done
+
+if [ "${NEXT}" != "" ]; then
+ echo "$(basename "$0"): option requires a value: --${NEXT}" 1>&2
+ usage 1>&2
+ exit 1
+fi
+
+fullpath() {
+ FULLPATH="${1}"
+ if [[ "$(uname -s)" == "MINGW"* ]]; then FULLPATH="$(cygpath -u "${1}")"; fi
+
+ if [[ "${FULLPATH}" != *"/"* ]]; then
+ FULLPATH="$(which "${FULLPATH}")"
+ if [ "$?" != "0" ]; then exit 1; fi
+ else
+ FULLPATH="$(cd "$(dirname "${FULLPATH}")" && pwd)/$(basename "${FULLPATH}")"
+ fi
+
+ if [[ "$(uname -s)" == "MINGW"* ]]; then FULLPATH="$(cygpath -w "${FULLPATH}")"; fi
+ echo "${FULLPATH}"
+}
+
+resources_dir() {
+ cd "$(dirname "$0")/../resources" && pwd
+}
+
+temp_dir() {
+ if [ "$(uname -s)" == "Darwin" ]; then
+ mktemp -dt libgit2_bench
+ else
+ mktemp -dt libgit2_bench.XXXXXXX
+ fi
+}
+
+create_preparescript() {
+ # add some functions for users to use in preparation
+ cat >> "${SANDBOX_DIR}/prepare.sh" << EOF
+ set -e
+
+ SANDBOX_DIR="${SANDBOX_DIR}"
+ RESOURCES_DIR="$(resources_dir)"
+
+ create_text_file() {
+ FILENAME="\${1}"
+ SIZE="\${2}"
+
+ if [ "\${FILENAME}" = "" ]; then
+ echo "usage: create_text_file <name> [size]" 1>&2
+ exit 1
+ fi
+
+ if [ "\${SIZE}" = "" ]; then
+ SIZE="1024"
+ fi
+
+ if [[ "\$(uname -s)" == "MINGW"* ]]; then
+ EOL="\r\n"
+ EOL_LEN="2"
+ CONTENTS="This is a reproducible text file. (With Unix line endings.)\n"
+ CONTENTS_LEN="60"
+ else
+ EOL="\n"
+ EOL_LEN="1"
+ CONTENTS="This is a reproducible text file. (With DOS line endings.)\r\n"
+ CONTENTS_LEN="60"
+ fi
+
+ rm -f "\${FILENAME:?}"
+ touch "\${FILENAME}"
+
+ if [ "\${SIZE}" -ge "\$((\${CONTENTS_LEN} + \${EOL_LEN}))" ]; then
+ SIZE="\$((\${SIZE} - \${CONTENTS_LEN}))"
+ COUNT="\$(((\${SIZE} - \${EOL_LEN}) / \${CONTENTS_LEN}))"
+
+ if [ "\${SIZE}" -gt "\${EOL_LEN}" ]; then
+ dd if="\${FILENAME}" of="\${FILENAME}" bs="\${CONTENTS_LEN}" seek=1 count="\${COUNT}" 2>/dev/null
+ fi
+
+ SIZE="\$((\${SIZE} - (\${COUNT} * \${CONTENTS_LEN})))"
+ fi
+
+ while [ "\${SIZE}" -gt "\${EOL_LEN}" ]; do
+ echo -ne "." >> "\${FILENAME}"
+ SIZE="\$((\${SIZE} - 1))"
+ done
+
+ if [ "\${SIZE}" = "\${EOL_LEN}" ]; then
+ echo -ne "\${EOL}" >> "\${FILENAME}"
+ SIZE="\$((\${SIZE} - \${EOL_LEN}))"
+ else
+ while [ "\${SIZE}" -gt "0" ]; do
+ echo -ne "." >> "\${FILENAME}"
+ SIZE="\$((\${SIZE} - 1))"
+ done
+ fi
+ }
+
+ create_random_file() {
+ FILENAME="\${1}"
+ SIZE="\${2}"
+
+ if [ "\${FILENAME}" = "" ]; then
+ echo "usage: create_random_file <name> [size]" 1>&2
+ exit 1
+ fi
+
+ if [ "\${SIZE}" = "" ]; then
+ SIZE="1024"
+ fi
+
+ dd if="/dev/urandom" of="\${FILENAME}" bs="\${SIZE}" count=1 2>/dev/null
+ }
+
+ flush_disk_cache() {
+ if [ "\$(uname -s)" = "Darwin" ]; then
+ sync && sudo purge
+ elif [ "\$(uname -s)" = "Linux" ]; then
+ sync && echo 3 | sudo tee /proc/sys/vm/drop_caches >/dev/null
+ elif [[ "\$(uname -s)" == "MINGW"* ]]; then
+ PurgeStandbyList
+ fi
+ }
+
+ sandbox() {
+ RESOURCE="\${1}"
+
+ if [ "\${RESOURCE}" = "" ]; then
+ echo "usage: sandbox <path>" 1>&2
+ exit 1
+ fi
+
+ if [ ! -d "\${RESOURCES_DIR}/\${RESOURCE}" ]; then
+ echo "sandbox: the resource \"\${RESOURCE}\" does not exist"
+ exit 1
+ fi
+
+ rm -rf "\${SANDBOX_DIR:?}/\${RESOURCE}"
+ cp -R "\${RESOURCES_DIR}/\${RESOURCE}" "\${SANDBOX_DIR}/"
+ }
+
+ sandbox_repo() {
+ RESOURCE="\${1}"
+
+ sandbox "\${RESOURCE}"
+
+ if [ -d "\${SANDBOX_DIR}/\${RESOURCE}/.gitted" ]; then
+ mv "\${SANDBOX_DIR}/\${RESOURCE}/.gitted" "\${SANDBOX_DIR}/\${RESOURCE}/.git";
+ fi
+ if [ -f "\${SANDBOX_DIR}/\${RESOURCE}/gitattributes" ]; then
+ mv "\${SANDBOX_DIR}/\${RESOURCE}/gitattributes" "\${SANDBOX_DIR}/\${RESOURCE}/.gitattributes";
+ fi
+ if [ -f "\${SANDBOX_DIR}/\${RESOURCE}/gitignore" ]; then
+ mv "\${SANDBOX_DIR}/\${RESOURCE}/gitignore" "\${SANDBOX_DIR}/\${RESOURCE}/.gitignore";
+ fi
+ }
+
+ cd "\${SANDBOX_DIR}"
+EOF
+
+ if [ "${PREPARE}" != "" ]; then
+ echo "" >> "${SANDBOX_DIR}/prepare.sh"
+ echo "${PREPARE}" >> "${SANDBOX_DIR}/prepare.sh"
+ fi
+
+ echo "${SANDBOX_DIR}/prepare.sh"
+}
+
+create_runscript() {
+ SCRIPT_NAME="${1}"; shift
+ CLI_PATH="${1}"; shift
+
+ if [[ "${CHDIR}" = "/"* ]]; then
+ START_DIR="${CHDIR}"
+ elif [ "${CHDIR}" != "" ]; then
+ START_DIR="${SANDBOX_DIR}/${CHDIR}"
+ else
+ START_DIR="${SANDBOX_DIR}"
+ fi
+
+ # our run script starts by chdir'ing to the sandbox or repository directory
+ echo -n "cd \"${START_DIR}\" && \"${CLI_PATH}\"" >> "${SANDBOX_DIR}/${SCRIPT_NAME}.sh"
+
+ for a in "$@"; do
+ echo -n " \"${a}\"" >> "${SANDBOX_DIR}/${SCRIPT_NAME}.sh"
+ done
+
+ echo "${SANDBOX_DIR}/${SCRIPT_NAME}.sh"
+}
+
+gitbench_usage() { echo "usage: gitbench command..."; }
+
+#
+# this is the function that the outer script calls to actually do the sandboxing and
+# invocation of hyperfine.
+#
+gitbench() {
+ NEXT=
+
+ # this test should run the given command in preparation of the tests
+ # this preparation script will be run _after_ repository creation and
+ # _before_ flushing the disk cache
+ PREPARE=
+
+ # this test should run within the given directory; this is a
+ # relative path beneath the sandbox directory.
+ CHDIR=
+
+ # this test should run `n` warmups
+ WARMUP=0
+
+ if [ "$*" = "" ]; then
+ gitbench_usage 1>&2
+ exit 1
+ fi
+
+ for a in "$@"; do
+ if [ "${NEXT}" = "warmup" ]; then
+ WARMUP="${a}"
+ NEXT=
+ elif [ "${NEXT}" = "prepare" ]; then
+ PREPARE="${a}"
+ NEXT=
+ elif [ "${NEXT}" = "chdir" ]; then
+ CHDIR="${a}"
+ NEXT=
+ elif [ "${a}" = "--warmup" ]; then
+ NEXT="warmup"
+ elif [ "${a}" = "--prepare" ]; then
+ NEXT="prepare"
+ elif [ "${a}" = "--chdir" ]; then
+ NEXT="chdir"
+ elif [[ "${a}" == "--"* ]]; then
+ echo "unknown argument: \"${a}\"" 1>&2
+ gitbench_usage 1>&2
+ exit 1
+ else
+ break
+ fi
+
+ shift
+ done
+
+ if [ "${NEXT}" != "" ]; then
+ echo "$(basename "$0"): option requires a value: --${NEXT}" 1>&2
+ gitbench_usage 1>&2
+ exit 1
+ fi
+
+ # sanity check
+
+ for a in "${SANDBOX[@]}"; do
+ if [ ! -d "$(resources_dir)/${a}" ]; then
+ echo "$0: no resource '${a}' found" 1>&2
+ exit 1
+ fi
+ done
+
+ if [ "$REPOSITORY" != "" ]; then
+ if [ ! -d "$(resources_dir)/${REPOSITORY}" ]; then
+ echo "$0: no repository resource '${REPOSITORY}' found" 1>&2
+ exit 1
+ fi
+ fi
+
+ # set up our sandboxing
+
+ SANDBOX_DIR="$(temp_dir)"
+
+ if [ "${BASELINE_CLI}" != "" ]; then
+ BASELINE_CLI_PATH=$(fullpath "${BASELINE_CLI}")
+ BASELINE_RUN_SCRIPT=$(create_runscript "baseline" "${BASELINE_CLI_PATH}" "$@")
+ fi
+ TEST_CLI_PATH=$(fullpath "${TEST_CLI}")
+ TEST_RUN_SCRIPT=$(create_runscript "test" "${TEST_CLI_PATH}" "$@")
+
+ PREPARE_SCRIPT="$(create_preparescript)"
+ ARGUMENTS=("--prepare" "bash ${PREPARE_SCRIPT}" "--warmup" "${WARMUP}")
+
+ if [ "${OUTPUT_STYLE}" != "" ]; then
+ ARGUMENTS+=("--style" "${OUTPUT_STYLE}")
+ fi
+
+ if [ "${SHOW_OUTPUT}" != "" ]; then
+ ARGUMENTS+=("--show-output")
+ fi
+
+ if [ "$JSON" != "" ]; then
+ ARGUMENTS+=("--export-json" "${JSON}")
+ fi
+
+ if [ "${BASELINE_CLI}" != "" ]; then
+ ARGUMENTS+=("-n" "${BASELINE_CLI} $*" "bash ${BASELINE_RUN_SCRIPT}")
+ fi
+
+ ARGUMENTS+=("-n" "${TEST_CLI} $*" "bash ${TEST_RUN_SCRIPT}")
+
+ hyperfine "${ARGUMENTS[@]}"
+ rm -rf "${SANDBOX_DIR:?}"
+}
diff --git a/tests/benchmarks/hash-object__text_100kb b/tests/benchmarks/hash-object__text_100kb
new file mode 100755
index 0000000..d77f224
--- /dev/null
+++ b/tests/benchmarks/hash-object__text_100kb
@@ -0,0 +1,7 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "create_text_file text_100kb 102400 &&
+ flush_disk_cache" \
+ hash-object "text_100kb"
diff --git a/tests/benchmarks/hash-object__text_10mb b/tests/benchmarks/hash-object__text_10mb
new file mode 100755
index 0000000..215afc6
--- /dev/null
+++ b/tests/benchmarks/hash-object__text_10mb
@@ -0,0 +1,7 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "create_text_file text_10mb 10485760 &&
+ flush_disk_cache" \
+ hash-object "text_10mb"
diff --git a/tests/benchmarks/hash-object__text_1kb b/tests/benchmarks/hash-object__text_1kb
new file mode 100755
index 0000000..1348b2f
--- /dev/null
+++ b/tests/benchmarks/hash-object__text_1kb
@@ -0,0 +1,7 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "create_text_file text_1kb 1024 &&
+ flush_disk_cache" \
+ hash-object "text_1kb"
diff --git a/tests/benchmarks/hash-object__text_cached_100kb b/tests/benchmarks/hash-object__text_cached_100kb
new file mode 100755
index 0000000..7c2a841
--- /dev/null
+++ b/tests/benchmarks/hash-object__text_cached_100kb
@@ -0,0 +1,7 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "create_text_file text_100kb 102400" \
+ --warmup 5 \
+ hash-object "text_100kb"
diff --git a/tests/benchmarks/hash-object__text_cached_10mb b/tests/benchmarks/hash-object__text_cached_10mb
new file mode 100755
index 0000000..311ddca
--- /dev/null
+++ b/tests/benchmarks/hash-object__text_cached_10mb
@@ -0,0 +1,7 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "create_text_file text_10mb 10485760" \
+ --warmup 5 \
+ hash-object "text_10mb"
diff --git a/tests/benchmarks/hash-object__text_cached_1kb b/tests/benchmarks/hash-object__text_cached_1kb
new file mode 100755
index 0000000..44c06ea
--- /dev/null
+++ b/tests/benchmarks/hash-object__text_cached_1kb
@@ -0,0 +1,7 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "create_text_file text_1kb 1024" \
+ --warmup 5 \
+ hash-object "text_1kb"
diff --git a/tests/benchmarks/hash-object__write_text_100kb b/tests/benchmarks/hash-object__write_text_100kb
new file mode 100755
index 0000000..fb72c09
--- /dev/null
+++ b/tests/benchmarks/hash-object__write_text_100kb
@@ -0,0 +1,9 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "sandbox_repo empty_standard_repo &&
+ create_text_file text_100kb 102400 &&
+ flush_disk_cache" \
+ --chdir "empty_standard_repo" \
+ hash-object -w "../text_100kb"
diff --git a/tests/benchmarks/hash-object__write_text_10mb b/tests/benchmarks/hash-object__write_text_10mb
new file mode 100755
index 0000000..9da0919
--- /dev/null
+++ b/tests/benchmarks/hash-object__write_text_10mb
@@ -0,0 +1,9 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "sandbox_repo empty_standard_repo &&
+ create_text_file text_10mb 10485760 &&
+ flush_disk_cache" \
+ --chdir "empty_standard_repo" \
+ hash-object "../text_10mb"
diff --git a/tests/benchmarks/hash-object__write_text_1kb b/tests/benchmarks/hash-object__write_text_1kb
new file mode 100755
index 0000000..ca34393
--- /dev/null
+++ b/tests/benchmarks/hash-object__write_text_1kb
@@ -0,0 +1,9 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "sandbox_repo empty_standard_repo &&
+ create_text_file text_1kb 1024 &&
+ flush_disk_cache" \
+ --chdir "empty_standard_repo" \
+ hash-object "../text_1kb"
diff --git a/tests/benchmarks/hash-object__write_text_cached_100kb b/tests/benchmarks/hash-object__write_text_cached_100kb
new file mode 100755
index 0000000..6803eee
--- /dev/null
+++ b/tests/benchmarks/hash-object__write_text_cached_100kb
@@ -0,0 +1,9 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "sandbox_repo empty_standard_repo &&
+ create_text_file text_100kb 102400" \
+ --warmup 5 \
+ --chdir "empty_standard_repo" \
+ hash-object "../text_100kb"
diff --git a/tests/benchmarks/hash-object__write_text_cached_10mb b/tests/benchmarks/hash-object__write_text_cached_10mb
new file mode 100755
index 0000000..4335cc8
--- /dev/null
+++ b/tests/benchmarks/hash-object__write_text_cached_10mb
@@ -0,0 +1,9 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "sandbox_repo empty_standard_repo &&
+ create_text_file text_10mb 10485760" \
+ --warmup 5 \
+ --chdir "empty_standard_repo" \
+ hash-object "../text_10mb"
diff --git a/tests/benchmarks/hash-object__write_text_cached_1kb b/tests/benchmarks/hash-object__write_text_cached_1kb
new file mode 100755
index 0000000..8a4c5c9
--- /dev/null
+++ b/tests/benchmarks/hash-object__write_text_cached_1kb
@@ -0,0 +1,9 @@
+#!/bin/bash -e
+
+. "$(dirname "$0")/benchmark_helpers.sh"
+
+gitbench --prepare "sandbox_repo empty_standard_repo &&
+ create_text_file text_1kb 1024" \
+ --warmup 5 \
+ --chdir "empty_standard_repo" \
+ hash-object "../text_1kb"