mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
91a8afa172
Method `metrics()` now pre-allocates slices for labels and results from query responses. This reduces the number of allocations on the hot path for instant requests. Signed-off-by: hagen1778 <roman@victoriametrics.com>
20 lines
488 B
Go
20 lines
488 B
Go
package datasource
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkMetrics(b *testing.B) {
|
|
payload := []byte(`[{"metric":{"__name__":"vm_rows"},"value":[1583786142,"13763"]},{"metric":{"__name__":"vm_requests", "foo":"bar", "baz": "qux"},"value":[1583786140,"2000"]}]`)
|
|
|
|
var pi promInstant
|
|
if err := json.Unmarshal(payload, &pi.Result); err != nil {
|
|
b.Fatalf(err.Error())
|
|
}
|
|
b.Run("Instant", func(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
_, _ = pi.metrics()
|
|
}
|
|
})
|
|
}
|