Created
March 28, 2019 09:08
-
-
Save benjbaron/83b4a1325f43413dd0ccc0f854c52e1b 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
func Benchmark_append(b *testing.B) { | |
b.StopTimer() | |
b.ReportAllocs() | |
b.StartTimer() | |
for i := 0; i < 1000; i++ { | |
var a []int | |
for i := 0; i < 100000; i++ { | |
a = append(a, i) | |
} | |
} | |
} | |
func Benchmark_noappend(b *testing.B) { | |
b.StopTimer() | |
b.ReportAllocs() | |
b.StartTimer() | |
for i := 0; i < 1000; i++ { | |
var a = make([]int, 100000) | |
for i := 0; i < 100000; i++ { | |
a[i] = i | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results: