Skip to content

Instantly share code, notes, and snippets.

@renanbastos93
Created January 10, 2022 10:08
Show Gist options
  • Save renanbastos93/75dd8d32c4653dc06c00cb7b33d13932 to your computer and use it in GitHub Desktop.
Save renanbastos93/75dd8d32c4653dc06c00cb7b33d13932 to your computer and use it in GitHub Desktop.
package main
import "testing"
func BenchmarkTestWithLength(b *testing.B) {
for i := 0; i < b.N; i++ {
useAppendWithLength()
}
}
func BenchmarkTestWithoutLength(b *testing.B) {
for i := 0; i < b.N; i++ {
useAppendWithoutLength()
}
}
func BenchmarkTestNotUseAppend(b *testing.B) {
for i := 0; i < b.N; i++ {
notUseAppend()
}
}
@renanbastos93
Copy link
Author

➜  benchtest-arr-go git:(main) ✗ go test -benchmem -bench=.         
goos: darwin
goarch: arm64
pkg: bench-append
BenchmarkTestWithLength-8      	  114627	      9291 ns/op	   81920 B/op	       1 allocs/op
BenchmarkTestWithoutLength-8   	   30699	     41421 ns/op	  386298 B/op	      20 allocs/op
BenchmarkTestNotUseAppend-8    	  287935	      4080 ns/op	   81920 B/op	       1 allocs/op
PASS
ok  	bench-append	4.273s```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment