| 1 |
# Benchmark libgit2 against the git reference implementation. |
| 2 |
name: Benchmark |
| 3 |
|
| 4 |
on: |
| 5 |
workflow_dispatch: |
| 6 |
inputs: |
| 7 |
suite: |
| 8 |
description: Benchmark suite to run |
| 9 |
debug: |
| 10 |
type: boolean |
| 11 |
description: Debugging output |
| 12 |
schedule: |
| 13 |
- cron: '15 4 * * *' |
| 14 |
|
| 15 |
permissions: |
| 16 |
contents: read |
| 17 |
|
| 18 |
jobs: |
| 19 |
# Run our benchmarks. We build a matrix with the various build |
| 20 |
# targets and their details. Unlike our CI builds, we run these |
| 21 |
# directly on the VM instead of in containers since we do not |
| 22 |
# need the breadth of platform diversity. |
| 23 |
build: |
| 24 |
# Only run scheduled workflows on the main repository; prevents people |
| 25 |
# from using build minutes on their forks. |
| 26 |
if: github.repository == 'libgit2/libgit2' |
| 27 |
|
| 28 |
strategy: |
| 29 |
matrix: |
| 30 |
platform: |
| 31 |
- name: "Linux (clang, OpenSSL)" |
| 32 |
id: linux |
| 33 |
os: ubuntu-latest |
| 34 |
setup-script: ubuntu |
| 35 |
env: |
| 36 |
CC: clang |
| 37 |
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 |
| 38 |
CMAKE_BUILD_OPTIONS: --config Release |
| 39 |
- name: "macOS" |
| 40 |
id: macos |
| 41 |
os: macos-latest |
| 42 |
setup-script: osx |
| 43 |
env: |
| 44 |
CC: clang |
| 45 |
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 |
| 46 |
CMAKE_BUILD_OPTIONS: --config Release |
| 47 |
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig |
| 48 |
- name: "Windows (amd64, Visual Studio)" |
| 49 |
id: windows |
| 50 |
os: windows-2022 |
| 51 |
setup-script: win32 |
| 52 |
env: |
| 53 |
ARCH: amd64 |
| 54 |
CMAKE_GENERATOR: Visual Studio 17 2022 |
| 55 |
CMAKE_OPTIONS: -A x64 -DDEPRECATE_HARD=ON -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release |
| 56 |
CMAKE_BUILD_OPTIONS: --config Release |
| 57 |
fail-fast: false |
| 58 |
name: "Benchmark ${{ matrix.platform.name }}" |
| 59 |
env: ${{ matrix.platform.env }} |
| 60 |
runs-on: ${{ matrix.platform.os }} |
| 61 |
steps: |
| 62 |
- name: Check out repository |
| 63 |
uses: actions/checkout@v4 |
| 64 |
with: |
| 65 |
path: source |
| 66 |
fetch-depth: 0 |
| 67 |
- name: Set up benchmark environment |
| 68 |
run: source/ci/setup-${{ matrix.platform.setup-script }}-benchmark.sh |
| 69 |
shell: bash |
| 70 |
if: matrix.platform.setup-script != '' |
| 71 |
- name: Clone resource repositories |
| 72 |
run: | |
| 73 |
mkdir resources |
| 74 |
git clone --bare https://github.com/git/git resources/git |
| 75 |
git clone --bare https://github.com/torvalds/linux resources/linux |
| 76 |
- name: Build |
| 77 |
run: | |
| 78 |
mkdir build && cd build |
| 79 |
../source/ci/build.sh |
| 80 |
shell: bash |
| 81 |
- name: Benchmark |
| 82 |
run: | |
| 83 |
export BENCHMARK_GIT_REPOSITORY="$(pwd)/resources/git" |
| 84 |
# avoid linux temporarily; the linux blame benchmarks are simply |
| 85 |
# too slow to use |
| 86 |
# export BENCHMARK_LINUX_REPOSITORY="$(pwd)/resources/linux" |
| 87 |
|
| 88 |
if [[ "$(uname -s)" == MINGW* ]]; then |
| 89 |
GIT2_CLI="$(cygpath -w $(pwd))\\build\\Release\\git2" |
| 90 |
else |
| 91 |
GIT2_CLI="$(pwd)/build/git2" |
| 92 |
fi |
| 93 |
|
| 94 |
if [ "${{ github.event.inputs.suite }}" != "" ]; then |
| 95 |
SUITE_FLAG="--suite ${{ github.event.inputs.suite }}" |
| 96 |
fi |
| 97 |
|
| 98 |
if [ "${{ github.event.inputs.debug }}" = "true" ]; then |
| 99 |
DEBUG_FLAG="--debug" |
| 100 |
fi |
| 101 |
|
| 102 |
mkdir benchmark && cd benchmark |
| 103 |
../source/tests/benchmarks/benchmark.sh \ |
| 104 |
${SUITE_FLAG} ${DEBUG_FLAG} \ |
| 105 |
--baseline-cli "git" --cli "${GIT2_CLI}" --name libgit2 \ |
| 106 |
--json benchmarks.json --zip benchmarks.zip |
| 107 |
shell: bash |
| 108 |
- name: Upload results |
| 109 |
uses: actions/upload-artifact@v4 |
| 110 |
with: |
| 111 |
name: benchmark-${{ matrix.platform.id }} |
| 112 |
path: benchmark |
| 113 |
if: always() |
| 114 |
|
| 115 |
# Publish the results |
| 116 |
publish: |
| 117 |
name: Publish results |
| 118 |
needs: [ build ] |
| 119 |
if: always() && github.repository == 'libgit2/libgit2' && github.event_name == 'schedule' |
| 120 |
runs-on: ubuntu-latest |
| 121 |
steps: |
| 122 |
- name: Check out benchmark repository |
| 123 |
uses: actions/checkout@v4 |
| 124 |
with: |
| 125 |
repository: libgit2/benchmarks |
| 126 |
path: site |
| 127 |
fetch-depth: 0 |
| 128 |
ssh-key: ${{ secrets.BENCHMARKS_PUBLISH_KEY }} |
| 129 |
- name: Download test results |
| 130 |
uses: actions/download-artifact@v4 |
| 131 |
- name: Publish API |
| 132 |
run: | |
| 133 |
# Move today's benchmark run into the right place |
| 134 |
for platform in linux macos windows; do |
| 135 |
TIMESTAMP=$(jq .time.start < "benchmark-${platform}/benchmarks.json") |
| 136 |
TIMESTAMP_LEN=$(echo -n ${TIMESTAMP} | wc -c | xargs) |
| 137 |
DENOMINATOR=1 |
| 138 |
if [ "${TIMESTAMP_LEN}" = "19" ]; then |
| 139 |
DENOMINATOR="1000000000" |
| 140 |
elif [ "${TIMESTAMP_LEN}" = "13" ]; then |
| 141 |
DENOMINATOR="1000" |
| 142 |
else |
| 143 |
echo "unknown timestamp" |
| 144 |
exit 1 |
| 145 |
fi |
| 146 |
|
| 147 |
if [[ "$(uname -s)" == "Darwin" ]]; then |
| 148 |
DATE=$(date -R -r $(("${TIMESTAMP}/${DENOMINATOR}")) +"%Y-%m-%d") |
| 149 |
else |
| 150 |
DATE=$(date -d @$(("${TIMESTAMP}/${DENOMINATOR}")) +"%Y-%m-%d") |
| 151 |
fi |
| 152 |
|
| 153 |
mkdir -p "site/public/api/runs/${DATE}" |
| 154 |
cp "benchmark-${platform}/benchmarks.json" "site/public/api/runs/${DATE}/${platform}.json" |
| 155 |
done |
| 156 |
|
| 157 |
(cd site && node scripts/aggregate.js) |
| 158 |
|
| 159 |
( |
| 160 |
cd site && |
| 161 |
git config user.name 'Benchmark Site Generation' && |
| 162 |
git config user.email '[email protected]' && |
| 163 |
git add . && |
| 164 |
git commit --allow-empty -m"benchmark update ${DATE}" && |
| 165 |
git push origin main |
| 166 |
) |
| 167 |
shell: bash |