Created
April 16, 2015 18:23
-
-
Save tarrsalah/74e663fa3eb2e074a344 to your computer and use it in GitHub Desktop.
append
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 slices | |
| import ( | |
| "testing" | |
| ) | |
| var length = 10000 | |
| func BenchmarkAppend(b *testing.B) { | |
| for i := 0; i < b.N; i++ { | |
| Append() | |
| } | |
| } | |
| func BenchmarkAppendFixed(b *testing.B) { | |
| for i := 0; i < b.N; i++ { | |
| AppendFixed() | |
| } | |
| } | |
| func Append() { | |
| var b []int | |
| for i := 0; i < length; i++ { | |
| b = append(b, i) | |
| } | |
| } | |
| func AppendFixed() { | |
| b := make([]int, 0, length) | |
| for i := 0; i < length; i++ { | |
| b = append(b, i) | |
| } | |
| } |
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
| PASS | |
| BenchmarkAppend 3000 430755 ns/op | |
| BenchmarkAppendFixed 10000 121799 ns/op | |
| ok github.com/tarrsalah/misc/spec/slices 2.572s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment