Debian Codegraph @

statsd/statsd_benchmark_test.go

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