Created
February 13, 2015 19:47
-
-
Save sekimura/416b94683d233f066dbd to your computer and use it in GitHub Desktop.
This file contains 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 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