Skip to content

Commit 01880dc

Browse files
committed
Add benchmarks for marshalling
Signed-off-by: Jeanette Tan <[email protected]>
1 parent 14a8016 commit 01880dc

File tree

2 files changed

+287
-261
lines changed

2 files changed

+287
-261
lines changed

model/value_float_test.go

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,42 @@ import (
2020
"testing"
2121
)
2222

23+
var (
24+
samplePairMatrixPlain = `[{"metric":{"__name__":"test_metric"},"values":[[1234.567,"123.1"],[12345.678,"123.12"]]},{"metric":{"foo":"bar"},"values":[[2234.567,"223.1"],[22345.678,"223.12"]]}]`
25+
samplePairMatrixValue = Matrix{
26+
&SampleStream{
27+
Metric: Metric{
28+
MetricNameLabel: "test_metric",
29+
},
30+
Values: []SamplePair{
31+
{
32+
Value: 123.1,
33+
Timestamp: 1234567,
34+
},
35+
{
36+
Value: 123.12,
37+
Timestamp: 12345678,
38+
},
39+
},
40+
},
41+
&SampleStream{
42+
Metric: Metric{
43+
"foo": "bar",
44+
},
45+
Values: []SamplePair{
46+
{
47+
Value: 223.1,
48+
Timestamp: 2234567,
49+
},
50+
{
51+
Value: 223.12,
52+
Timestamp: 22345678,
53+
},
54+
},
55+
},
56+
}
57+
)
58+
2359
func TestEqualValues(t *testing.T) {
2460
tests := map[string]struct {
2561
in1, in2 SampleValue
@@ -231,39 +267,8 @@ func TestMatrixJSON(t *testing.T) {
231267
value: Matrix{},
232268
},
233269
{
234-
plain: `[{"metric":{"__name__":"test_metric"},"values":[[1234.567,"123.1"],[12345.678,"123.12"]]},{"metric":{"foo":"bar"},"values":[[2234.567,"223.1"],[22345.678,"223.12"]]}]`,
235-
value: Matrix{
236-
&SampleStream{
237-
Metric: Metric{
238-
MetricNameLabel: "test_metric",
239-
},
240-
Values: []SamplePair{
241-
{
242-
Value: 123.1,
243-
Timestamp: 1234567,
244-
},
245-
{
246-
Value: 123.12,
247-
Timestamp: 12345678,
248-
},
249-
},
250-
},
251-
&SampleStream{
252-
Metric: Metric{
253-
"foo": "bar",
254-
},
255-
Values: []SamplePair{
256-
{
257-
Value: 223.1,
258-
Timestamp: 2234567,
259-
},
260-
{
261-
Value: 223.12,
262-
Timestamp: 22345678,
263-
},
264-
},
265-
},
266-
},
270+
plain: samplePairMatrixPlain,
271+
value: samplePairMatrixValue,
267272
},
268273
}
269274

@@ -291,3 +296,12 @@ func TestMatrixJSON(t *testing.T) {
291296
}
292297
}
293298
}
299+
300+
func BenchmarkJSONMarshallingSamplePairMatrix(b *testing.B) {
301+
for i := 0; i < b.N; i++ {
302+
_, err := json.Marshal(samplePairMatrixValue)
303+
if err != nil {
304+
b.Fatal("error marshalling")
305+
}
306+
}
307+
}

0 commit comments

Comments
 (0)