Created
March 17, 2014 22:25
-
-
Save jeddenlea/9609653 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
/* | |
jed@thevm:~/go/src/bench/copy$ go test --test.bench=. --test.benchtime=10s . | |
testing: warning: no tests to run | |
PASS | |
BenchmarkAppendNil 50000 627957 ns/op | |
BenchmarkMakeCopy 50000 627037 ns/op | |
BenchmarkAppendMake 50000 611550 ns/op' | |
And using a 1k 's'... | |
BenchmarkAppendNil 50000000 563 ns/op | |
BenchmarkMakeCopy 50000000 579 ns/op | |
BenchmarkAppendMake 50000000 529 ns/op | |
*/ | |
package copy_bench | |
import ( | |
"testing" | |
) | |
var s = make([]byte, 1024*1024*5) | |
func BenchmarkAppendNil(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
_ = append([]byte(nil), s...) | |
} | |
} | |
func BenchmarkMakeCopy(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
n := make([]byte, len(s)) | |
copy(n, s) | |
} | |
} | |
func BenchmarkAppendMake(b *testing.B) { | |
for i:=0; i < b.N; i++{ | |
_ = append(make([]byte, 0, len(s)), s...) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment