Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misakwa/0de125b97aba9f53632faebc9861e360 to your computer and use it in GitHub Desktop.
Save misakwa/0de125b97aba9f53632faebc9861e360 to your computer and use it in GitHub Desktop.
package bench_test
import "testing"
func BenchmarkByteArray(b *testing.B) {
for n := 0; n < b.N; n++ {
GetBytes()
}
}
func BenchmarkString(b *testing.B) {
for n := 0; n < b.N; n++ {
GetString()
}
}
func GetString() string {
filtersKey := make([]string, 0, 0)
filtersKey = append(filtersKey, "chunks = ?")
filtersKey = append(filtersKey, "error_message = ?")
filtersKey = append(filtersKey, "error_status = ?")
filtersKey = append(filtersKey, "status = ?")
return ""
}
func GetBytes() string {
var filtersKey []byte
filtersKey = append(filtersKey, "chunks = ?"...)
filtersKey = append(filtersKey, "error_message = ?"...)
filtersKey = append(filtersKey, "error_status = ?"...)
filtersKey = append(filtersKey, "status = ?"...)
return ""
}
@misakwa
Copy link
Author

misakwa commented Oct 24, 2016

$ go test -v -benchmem -bench=.
testing: warning: no tests to run
BenchmarkByteArray-4    10000000               120 ns/op             112 B/op          3 allocs/op
BenchmarkString-4       10000000               209 ns/op             112 B/op          3 allocs/op

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment