1package statsd
2
3import (
4	"fmt"
5	"testing"
6	"time"
7)
8
9var payloadSink []byte
10
11func benchmarkFormat(b *testing.B, tagsNumber int) {
12	payloadSink = make([]byte, 0, 1024*8)
13	var tags []string
14	for i := 0; i < tagsNumber; i++ {
15		tags = append(tags, fmt.Sprintf("tag%d:tag%d\n", i, i))
16	}
17	event := Event{
18		Title:          "EvenTitle",
19		Text:           "EventText",
20		Timestamp:      time.Date(2016, time.August, 15, 0, 0, 0, 0, time.UTC),
21		Hostname:       "hostname",
22		AggregationKey: "aggregationKey",
23		Priority:       "priority",
24		SourceTypeName: "SourceTypeName",
25		AlertType:      "alertType",
26		Tags:           tags,
27	}
28	serviceCheck := ServiceCheck{
29		Name:      "service.check",
30		Status:    Ok,
31		Timestamp: time.Date(2016, time.August, 15, 0, 0, 0, 0, time.UTC),
32		Hostname:  "hostname",
33		Message:   "message",
34		Tags:      []string{"tag1:tag1"},
35	}
36	b.ResetTimer()
37	for n := 0; n < b.N; n++ {
38		payloadSink = appendGauge(payloadSink[:0], "namespace", []string{}, "metric", 1, tags, 0.1)
39		payloadSink = appendCount(payloadSink[:0], "namespace", []string{}, "metric", 1, tags, 0.1)
40		payloadSink = appendHistogram(payloadSink[:0], "namespace", []string{}, "metric", 1, tags, 0.1)
41		payloadSink = appendDistribution(payloadSink[:0], "namespace", []string{}, "metric", 1, tags, 0.1)
42		payloadSink = appendSet(payloadSink[:0], "namespace", []string{}, "metric", "setelement", tags, 0.1)
43		payloadSink = appendTiming(payloadSink[:0], "namespace", []string{}, "metric", 1, tags, 0.1)
44		payloadSink = appendEvent(payloadSink[:0], event, []string{})
45		payloadSink = appendServiceCheck(payloadSink[:0], serviceCheck, []string{})
46	}
47}
48
49func BenchmarkFormat0(b *testing.B)   { benchmarkFormat(b, 0) }
50func BenchmarkFormat1(b *testing.B)   { benchmarkFormat(b, 1) }
51func BenchmarkFormat5(b *testing.B)   { benchmarkFormat(b, 5) }
52func BenchmarkFormat10(b *testing.B)  { benchmarkFormat(b, 10) }
53func BenchmarkFormat50(b *testing.B)  { benchmarkFormat(b, 50) }
54func BenchmarkFormat100(b *testing.B) { benchmarkFormat(b, 100) }
55