Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
name: Benchmark
on:
push:
branches: [ "main", "master" ]
pull_request:
branches: [ "main", "master" ]
# Runs only on demand or on a schedule so CI minutes aren't burned on every push.
schedule:
- cron: "0 3 * * 1" # weekly (Mon 03:00 UTC)
workflow_dispatch:
inputs:
benchtime:
description: Duration per benchmark (go -benchtime)
required: false
default: "1s"
count:
description: Number of runs per benchmark (go -count); median of runs is reported
required: false
default: "3"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
BENCHTIME: ${{ inputs.benchtime || '1s' }}
BENCH_COUNT: ${{ inputs.count || '3' }}

jobs:
benchmark:
name: Benchmark (${{ matrix.db }})
Expand Down Expand Up @@ -66,7 +78,6 @@ jobs:
save-benchmarks:
name: Save Benchmark JSON
needs: benchmark
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down Expand Up @@ -94,7 +105,7 @@ jobs:
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add benchmark/benchmarks.json
git commit -m "chore(benchmark): update benchmark/benchmarks.json [skip ci]"
git commit -m "chore(benchmark): update benchmark results [skip ci]"
git push
else
echo "No benchmark results changed."
Expand Down
3 changes: 3 additions & 0 deletions benchmark/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package main

import (
"fmt"
"math/rand"
"testing"
)

// Mirrors the shuffle technique used by github.com/efectn/go-orm-benchmarks.
func orms(b *testing.B, fns map[string]func(*testing.B)) {
order := []string{"Raw", "Phi", "Bun", "Ent", "GORM"}
rand.Shuffle(len(order), func(i, j int) { order[i], order[j] = order[j], order[i] })
for _, name := range order {
if fn, ok := fns[name]; ok {
b.Run(name, fn)
Expand Down
Loading
Loading