Skip to content

Instantly share code, notes, and snippets.

@sekimura
Created February 13, 2015 19:47
Show Gist options
  • Save sekimura/416b94683d233f066dbd to your computer and use it in GitHub Desktop.
Save sekimura/416b94683d233f066dbd to your computer and use it in GitHub Desktop.
package bench_test
import "testing"
func BenchmarkMemAllocOndemand(b *testing.B) {
n := 10
b.ResetTimer()
for i := 0; i < b.N; i++ {
s := make([]string, 0)
for j := 0; j < n; j++ {
s = append(s, "alice")
}
}
}
func BenchmarkMemAllocAllBeforeUsing(b *testing.B) {
n := 10
b.ResetTimer()
for i := 0; i < b.N; i++ {
s := make([]string, 0, n)
for j := 0; j < n; j++ {
s = append(s, "alice")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment