Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "strconv"
- "strings"
- "testing"
- )
- func dummy(s string) {}
- func BenchmarkStringBuilder(b *testing.B) {
- for i := 0; i < b.N; i++ {
- var b strings.Builder
- b.WriteString("a=")
- fmt.Fprintf(&b, "%d", 12345)
- dummy(b.String())
- }
- }
- func BenchmarkByteSlice(b *testing.B) {
- for i := 0; i < b.N; i++ {
- var b []byte
- b = append(b, "a="...)
- b = strconv.AppendInt(b, 12345, 10)
- dummy(string(b))
- }
- }
- func BenchmarkStringList(b *testing.B) {
- for i := 0; i < b.N; i++ {
- var b []string
- b = append(b, "a=")
- b = append(b, fmt.Sprintf("%d", 12345))
- dummy(strings.Join(b, ""))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement