Created
September 17, 2014 22:48
-
-
Save capoferro/2e957b25080ad1e7726f to your computer and use it in GitHub Desktop.
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 main | |
import ( | |
"testing" | |
) | |
func BenchmarkAaa(b *testing.B) { | |
ints := make([]int, 0) | |
for i := 0; i < b.N; i++ { | |
ints = append(ints, i) | |
} | |
} | |
func BenchmarkBbb(b *testing.B) { | |
ints := make([]int, b.N) | |
for i := 0; i < b.N; i++ { | |
ints[i] = i | |
} | |
} |
For some reason flipping the run order of the benchmarks makes Aaa take much longer.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BenchmarkAaa 200000000 7.62 ns/op
BenchmarkBbb 2000000000 36.7 ns/op