prometheus/storage/metric/sample_test.go
Julius Volz 1eee448bc1 Store samples in custom binary encoding.
This has been shown to provide immense decoding speed benefits.

See also:

https://groups.google.com/forum/#!topic/prometheus-developers/FeGl_qzGrYs

Change-Id: I7d45b4650e44ddecaa91dad9d7fdb3cd0b9f15fe
2014-03-09 22:31:38 +01:00

54 lines
1.0 KiB
Go

package metric
import (
"math/rand"
"testing"
clientmodel "github.com/prometheus/client_golang/model"
)
const numTestValues = 5000
func TestValuesMarshalAndUnmarshal(t *testing.T) {
values := randomValues(numTestValues)
marshalled := values.marshal()
unmarshalled := unmarshalValues(marshalled)
for i, expected := range values {
actual := unmarshalled[i]
if !actual.Equal(expected) {
t.Fatalf("%d. got: %v, expected: %v", i, actual, expected)
}
}
}
func randomValues(numSamples int) Values {
v := make(Values, 0, numSamples)
for i := 0; i < numSamples; i++ {
v = append(v, &SamplePair{
Timestamp: clientmodel.Timestamp(rand.Int63()),
Value: clientmodel.SampleValue(rand.NormFloat64()),
})
}
return v
}
func BenchmarkMarshal(b *testing.B) {
v := randomValues(numTestValues)
b.ResetTimer()
for i := 0; i < b.N; i++ {
v.marshal()
}
}
func BenchmarkUnmarshal(b *testing.B) {
v := randomValues(numTestValues)
marshalled := v.marshal()
b.ResetTimer()
for i := 0; i < b.N; i++ {
unmarshalValues(marshalled)
}
}