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