Skip to content

Instantly share code, notes, and snippets.

@DeedleFake
Last active February 13, 2026 20:42
Show Gist options
  • Select an option

  • Save DeedleFake/2f50b02c0708484c66d18253302c4fd6 to your computer and use it in GitHub Desktop.

Select an option

Save DeedleFake/2f50b02c0708484c66d18253302c4fd6 to your computer and use it in GitHub Desktop.
Go 1.26 cgo Benchmark

Go 1.26 cgo Benchmark

This is an extremely simple benchmark of the cgo performance improvements in Go 1.26.

Results

goos: linux
goarch: amd64
pkg: test
cpu: AMD Ryzen 9 3900X 12-Core Processor            
       │ go1.25.txt  │             go1.26.txt              │
       │   sec/op    │   sec/op     vs base                │
Add-24   50.12n ± 3%   26.52n ± 1%  -47.08% (p=0.000 n=10)

       │ go1.25.txt │           go1.26.txt           │
       │    B/op    │    B/op     vs base            │
Add-24   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

       │ go1.25.txt │           go1.26.txt           │
       │ allocs/op  │ allocs/op   vs base            │
Add-24   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal
module test
go 1.25.7
goos: linux
goarch: amd64
pkg: test
cpu: AMD Ryzen 9 3900X 12-Core Processor
BenchmarkAdd-24 24672879 50.24 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 24842866 49.66 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 23953146 50.05 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 24052581 50.54 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 24633309 47.81 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 24236566 48.74 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 24326767 49.98 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 23441038 50.35 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 23992288 50.18 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 24074400 50.30 ns/op 0 B/op 0 allocs/op
PASS
ok test 12.066s
goos: linux
goarch: amd64
pkg: test
cpu: AMD Ryzen 9 3900X 12-Core Processor
BenchmarkAdd-24 45638282 26.50 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 41911680 26.67 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 45225888 26.67 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 45311896 26.68 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 44342197 26.44 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 44602566 26.44 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 45509528 26.54 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 45564736 26.55 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 44621707 26.45 ns/op 0 B/op 0 allocs/op
BenchmarkAdd-24 44866058 26.32 ns/op 0 B/op 0 allocs/op
PASS
ok test 11.880s
#include "test.h"
int add(int a, int b) {
return a + b;
}
package test
/*
#include "test.h"
*/
import "C"
func Add(a, b int) int {
return int(C.add(C.int(a), C.int(b)))
}
int add(int, int);
package test_test
import (
"math/rand/v2"
"test"
"testing"
)
func BenchmarkAdd(b *testing.B) {
v1, v2 := rand.Int(), rand.Int()
b.ResetTimer()
for b.Loop() {
test.Add(v1, v2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment