Created
December 8, 2014 17:07
-
-
Save anacrolix/e8baa9c70bbb2b909b19 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 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