Created
October 1, 2014 13:08
-
-
Save creack/9e0e46463ecc1d6a7148 to your computer and use it in GitHub Desktop.
gobrake slice pointer vs non pointer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
}) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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