MCPcopy Create free account
hub / github.com/prometheus/common / BenchmarkSamplesJSONUnmarshal

Function BenchmarkSamplesJSONUnmarshal

model/api_bench_test.go:102–140  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

100}
101
102func BenchmarkSamplesJSONUnmarshal(b *testing.B) {
103 for _, timeseriesCount := range []int{10, 100, 1000} {
104 b.Run("series="+strconv.Itoa(timeseriesCount), func(b *testing.B) {
105 for _, datapointCount := range []int{10, 100, 1000} {
106 b.Run("dp="+strconv.Itoa(datapointCount), func(b *testing.B) {
107 floats, histograms := generateData(timeseriesCount, datapointCount)
108
109 floatBytes, err := json.Marshal(floats)
110 if err != nil {
111 b.Fatalf("Error marshaling: %v", err)
112 }
113 histogramBytes, err := json.Marshal(histograms)
114 if err != nil {
115 b.Fatalf("Error marshaling: %v", err)
116 }
117
118 b.Run("type=floats", func(b *testing.B) {
119 b.ReportAllocs()
120 for b.Loop() {
121 var m Matrix
122 if err := json.Unmarshal(floatBytes, &m); err != nil {
123 b.Fatal(err)
124 }
125 }
126 })
127 b.Run("type=histograms", func(b *testing.B) {
128 b.ReportAllocs()
129 for b.Loop() {
130 var m Matrix
131 if err := json.Unmarshal(histogramBytes, &m); err != nil {
132 b.Fatal(err)
133 }
134 }
135 })
136 })
137 }
138 })
139 }
140}

Callers

nothing calls this directly

Calls 1

generateDataFunction · 0.85

Tested by

no test coverage detected