2023-12-21 16:29:10 +00:00
|
|
|
package datadogv2
|
2021-09-28 19:47:45 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2023-12-21 16:29:10 +00:00
|
|
|
func BenchmarkRequestUnmarshalJSON(b *testing.B) {
|
2021-09-28 19:47:45 +00:00
|
|
|
reqBody := []byte(`{
|
|
|
|
"series": [
|
|
|
|
{
|
|
|
|
"metric": "system.load.1",
|
2023-12-21 16:29:10 +00:00
|
|
|
"type": 0,
|
2021-09-28 19:47:45 +00:00
|
|
|
"points": [
|
2023-12-21 16:29:10 +00:00
|
|
|
{
|
|
|
|
"timestamp": 1636629071,
|
|
|
|
"value": 0.7
|
|
|
|
}
|
2021-09-28 19:47:45 +00:00
|
|
|
],
|
2023-12-21 16:29:10 +00:00
|
|
|
"resources": [
|
|
|
|
{
|
|
|
|
"name": "dummyhost",
|
|
|
|
"type": "host"
|
|
|
|
}
|
2021-09-28 19:47:45 +00:00
|
|
|
],
|
2023-12-21 16:29:10 +00:00
|
|
|
"tags": ["environment:test"]
|
2021-09-28 19:47:45 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}`)
|
|
|
|
b.SetBytes(int64(len(reqBody)))
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
2023-12-05 00:30:40 +00:00
|
|
|
var req Request
|
2021-09-28 19:47:45 +00:00
|
|
|
for pb.Next() {
|
2023-12-21 16:29:10 +00:00
|
|
|
if err := UnmarshalJSON(&req, reqBody); err != nil {
|
2021-09-28 19:47:45 +00:00
|
|
|
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)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|