Skip to content

Instantly share code, notes, and snippets.

@creack
Created October 1, 2014 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creack/9e0e46463ecc1d6a7148 to your computer and use it in GitHub Desktop.
Save creack/9e0e46463ecc1d6a7148 to your computer and use it in GitHub Desktop.
gobrake slice pointer vs non pointer
package gobrake
import "testing"
func BenchmarkSlicePtr(b *testing.B) {
var (
file = "file.go"
funcName = "func() error { return nil; }"
line = 42
)
for i := 0; i < b.N; i++ {
stack := []*StackFrame{}
for i := 0; i < 10e5; i++ {
stack = append(stack, &StackFrame{
File: file,
Line: line,
Func: funcName,
})
}
}
}
func BenchmarkSliceNonPtr(b *testing.B) {
var (
file = "file.go"
funcName = "func() error { return nil; }"
line = 42
)
for i := 0; i < b.N; i++ {
stack := []StackFrame{}
for i := 0; i < 10e5; i++ {
stack = append(stack, StackFrame{
File: file,
Line: line,
Func: funcName,
})
}
}
}
BenchmarkSlicePtr 10 131220169 ns/op
BenchmarkSliceNonPtr 20 73342001 ns/op
ok github.com/airbrake/gobrake 3.083s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment