1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
package statsd
import (
"fmt"
"strconv"
"testing"
)
var statBytes []byte
var stat string
// Results:
// BenchmarkStatBuildGauge_Sprintf-8 500 45699958 ns/op
// BenchmarkStatBuildGauge_Concat-8 1000 23452863 ns/op
// BenchmarkStatBuildGauge_BytesAppend-8 1000 21705121 ns/op
func BenchmarkStatBuildGauge_Sprintf(b *testing.B) {
for n := 0; n < b.N; n++ {
for x := 0; x < 100000; x++ {
stat = fmt.Sprintf("%f|g", 3.14159)
}
}
}
func BenchmarkStatBuildGauge_Concat(b *testing.B) {
for n := 0; n < b.N; n++ {
for x := 0; x < 100000; x++ {
stat = strconv.FormatFloat(3.14159, 'f', -1, 64) + "|g"
}
}
}
func BenchmarkStatBuildGauge_BytesAppend(b *testing.B) {
suffix := []byte("|g")
for n := 0; n < b.N; n++ {
for x := 0; x < 100000; x++ {
statBytes = []byte{}
statBytes = append(strconv.AppendFloat(statBytes, 3.14159, 'f', -1, 64), suffix...)
}
}
}
func BenchmarkStatBuildCount_Sprintf(b *testing.B) {
for n := 0; n < b.N; n++ {
for x := 0; x < 100000; x++ {
stat = fmt.Sprintf("%d|c", 314)
}
}
}
func BenchmarkStatBuildCount_Concat(b *testing.B) {
for n := 0; n < b.N; n++ {
for x := 0; x < 100000; x++ {
stat = strconv.FormatInt(314, 10) + "|c"
}
}
}
func BenchmarkStatBuildCount_BytesAppend(b *testing.B) {
suffix := []byte("|c")
for n := 0; n < b.N; n++ {
for x := 0; x < 100000; x++ {
statBytes = []byte{}
statBytes = append(strconv.AppendInt(statBytes, 314, 10), suffix...)
}
}
}
|