Created
September 17, 2014 22:48
-
-
Save capoferro/2e957b25080ad1e7726f 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 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 | |
} | |
} |
BenchmarkBbb 2000000000 31.5 ns/op
BenchmarkAaa 50000000 27.8 ns/op
BenchmarkBbb 2000000000 36.0 ns/op
BenchmarkAaa 100000000 23.1 ns/op
BenchmarkAaa 200000000 7.62 ns/op
BenchmarkBbb 2000000000 36.7 ns/op
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 8.36 ns/op
BenchmarkBbb 2000000000 39.1 ns/op