Skip to content
Open
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
13 changes: 12 additions & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@ jobs:
LLGO_ROOT: ${{ github.workspace }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Determine pull request merge-base
if: github.event_name == 'pull_request'
id: merge-base
run: |
git fetch https://github.com/${{ github.event.pull_request.base.repo.full_name }}.git ${{ github.event.pull_request.base.ref }}
base_sha=$(git merge-base FETCH_HEAD ${{ github.event.pull_request.head.sha }})
echo "sha=$base_sha" >> "$GITHUB_OUTPUT"
echo "Computed pull request merge-base: $base_sha (head: ${{ github.event.pull_request.head.sha }})"

- name: Check out pull request base benchmark source
if: github.event_name == 'pull_request'
uses: actions/checkout@v7
with:
repository: ${{ github.event.pull_request.base.repo.full_name }}
ref: ${{ github.event.pull_request.base.sha }}
ref: ${{ steps.merge-base.outputs.sha }}
path: .benchmark/source
persist-credentials: false

Expand Down
6 changes: 3 additions & 3 deletions benchmark/baseline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ commit, branch, or pull-request series.

The program workloads reuse:

- `benchmark/binary_size/cprintf`: only `lib/c.Printf`;
- `benchmark/binary_size/println`: only the built-in `println`;
- `benchmark/binary_size/fmtprintf`: `fmt.Printf`.
- `benchmark/binary_size/cprintf`: only `lib/c.Printf` (default and `-lto=full`);
- `benchmark/binary_size/println`: only the built-in `println` (default and `-lto=full`);
- `benchmark/binary_size/fmtprintf`: `fmt.Printf` (default and `-lto=full`).

For each workload, the collector performs an unmeasured warm build, then records
median build time, median process time, file size, executable-code bytes,
Expand Down
10 changes: 8 additions & 2 deletions benchmark/baseline/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ type workload struct {
name string
source string
output string
flags []string
}

var workloads = []workload{
{name: "cprintf", source: "benchmark/binary_size/cprintf/main.go", output: "Hello, world\n"},
{name: "cprintf-lto", source: "benchmark/binary_size/cprintf/main.go", output: "Hello, world\n", flags: []string{"-lto=full"}},
{name: "println", source: "benchmark/binary_size/println/main.go", output: "Hello, world\n"},
{name: "println-lto", source: "benchmark/binary_size/println/main.go", output: "Hello, world\n", flags: []string{"-lto=full"}},
{name: "fmtprintf", source: "benchmark/binary_size/fmtprintf/main.go", output: "Hello, world\n"},
{name: "fmtprintf-lto", source: "benchmark/binary_size/fmtprintf/main.go", output: "Hello, world\n", flags: []string{"-lto=full"}},
}

var expectedGoBenchmarks = []string{
Expand Down Expand Up @@ -223,15 +227,17 @@ func collect(ctx context.Context, root, llgo, out string, buildRuns, runRuns int
var sizes, timings []metric
for _, item := range workloads {
binary := filepath.Join(binDir, item.name)
buildArgs := append([]string{"build"}, item.flags...)
buildArgs = append(buildArgs, "-o", binary, filepath.Join(root, item.source))
// Keep first-use toolchain and filesystem caches out of the measured
// median so the first revision is not systematically disadvantaged.
if err := run(ctx, env, io.Discard, llgo, "build", "-o", binary, filepath.Join(root, item.source)); err != nil {
if err := run(ctx, env, io.Discard, llgo, buildArgs...); err != nil {
return fmt.Errorf("warm build %s: %w", item.name, err)
}
buildDurations := make([]time.Duration, 0, buildRuns)
for range buildRuns {
start := time.Now()
if err := run(ctx, env, io.Discard, llgo, "build", "-o", binary, filepath.Join(root, item.source)); err != nil {
if err := run(ctx, env, io.Discard, llgo, buildArgs...); err != nil {
return fmt.Errorf("build %s: %w", item.name, err)
}
buildDurations = append(buildDurations, time.Since(start))
Expand Down
1 change: 1 addition & 0 deletions benchmark/baseline/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func TestExportBenchmarks(t *testing.T) {
"Unit file-bytes better=lower assume=exact",
"Unit build-ns better=lower",
"BenchmarkProgram/cprintf 1 1 file-bytes 1 text-bytes 1 data-bytes 1 bss-bytes 1 build-ns 1 run-ns",
"BenchmarkProgram/cprintf-lto 1 1 file-bytes 1 text-bytes 1 data-bytes 1 bss-bytes 1 build-ns 1 run-ns",
"BenchmarkRuntimeGetG-1 100 12.5 ns/op",
} {
if !strings.Contains(text, want) {
Expand Down
Loading
Loading