2023-12-21 16:29:10 +00:00
|
|
|
package datadogv1
|
2021-09-28 19:47:45 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkRequestUnmarshal(b *testing.B) {
|
|
|
|
reqBody := []byte(`{
|
|
|
|
"series": [
|
|
|
|
{
|
|
|
|
"host": "test.example.com",
|
|
|
|
"interval": 20,
|
|
|
|
"metric": "system.load.1",
|
2023-12-21 16:29:10 +00:00
|
|
|
"points": [[
|
2021-09-28 19:47:45 +00:00
|
|
|
1575317847,
|
|
|
|
0.5
|
2023-12-21 16:29:10 +00:00
|
|
|
]],
|
2021-09-28 19:47:45 +00:00
|
|
|
"tags": [
|
|
|
|
"environment:test"
|
|
|
|
],
|
|
|
|
"type": "rate"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}`)
|
|
|
|
b.SetBytes(int64(len(reqBody)))
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
2023-12-05 00:26:22 +00:00
|
|
|
var req Request
|
2021-09-28 19:47:45 +00:00
|
|
|
for pb.Next() {
|
|
|
|
if err := req.Unmarshal(reqBody); err != nil {
|
|
|
|
panic(fmt.Errorf("unexpected error: %w", err))
|
|
|
|
}
|
|
|
|
if len(req.Series) != 1 {
|
|
|
|
panic(fmt.Errorf("unexpected number of series unmarshaled: got %d; want 4", len(req.Series)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|