Skip to content

Instantly share code, notes, and snippets.

@anacrolix
Created December 8, 2014 17:07
Show Gist options
  • Save anacrolix/e8baa9c70bbb2b909b19 to your computer and use it in GitHub Desktop.
Save anacrolix/e8baa9c70bbb2b909b19 to your computer and use it in GitHub Desktop.
package append
import "testing"
var result []T
const size = 10000
type T int
func BenchmarkCopy(b *testing.B) {
orig := make([]T, size)
for n := 0; n < b.N; n++ {
cpy := make([]T, len(orig))
copy(cpy, orig)
orig = cpy
}
result = orig
}
func BenchmarkAppend(b *testing.B) {
orig := make([]T, size)
for n := 0; n < b.N; n++ {
cpy := append([]T{}, orig...)
orig = cpy
}
result = orig
}
func BenchmarkAppendPreCapped(b *testing.B) {
orig := make([]T, size)
for n := 0; n < b.N; n++ {
cpy := append(make([]T, 0, len(orig)), orig...)
orig = cpy
}
result = orig
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment