You can now use CodSpeed to benchmark Go codebases with the standard
testing
package and your existing go test
workflow! No code changes required!
The integration is available in our codspeed-go repository.
CodSpeed works with your regular go test -bench
runs. Write benchmarks with
testing
and CodSpeed will discover and run them.
Here is a simple example:
// fib_test.go
package example
import "testing"
func fib(n int) int {
if n < 2 {
return n
}
return fib(n-1) + fib(n-2)
}
func BenchmarkFibonacci10(b *testing.B) {
// Preferred loop helper for precision
for b.Loop() {
fib(10)
}
}
func BenchmarkFibonacci20(b *testing.B) {
// Traditional pattern also supported
for i := 0; i < b.N; i++ {
fib(20)
}
}
Check out our Go documentation for all details on how to get started!