2021-07-26 13:09:12 +02:00
|
|
|
//go:build !cgo
|
2019-07-23 18:26:39 +02:00
|
|
|
|
|
|
|
package encoding
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMarshalUnmarshalInt64Array(t *testing.T) {
|
2023-01-24 03:41:07 +01:00
|
|
|
r := rand.New(rand.NewSource(1))
|
|
|
|
|
2019-07-23 18:26:39 +02:00
|
|
|
var va []int64
|
|
|
|
var v int64
|
|
|
|
|
|
|
|
// Verify nearest delta encoding.
|
|
|
|
va = va[:0]
|
|
|
|
v = 0
|
|
|
|
for i := 0; i < 8*1024; i++ {
|
2023-01-24 03:41:07 +01:00
|
|
|
v += int64(r.NormFloat64() * 1e6)
|
2019-07-23 18:26:39 +02:00
|
|
|
va = append(va, v)
|
|
|
|
}
|
2023-04-06 06:38:37 +02:00
|
|
|
for precisionBits := uint8(1); precisionBits < 14; precisionBits++ {
|
2019-07-23 18:26:39 +02:00
|
|
|
testMarshalUnmarshalInt64Array(t, va, precisionBits, MarshalTypeZSTDNearestDelta)
|
|
|
|
}
|
|
|
|
for precisionBits := uint8(23); precisionBits < 65; precisionBits++ {
|
|
|
|
testMarshalUnmarshalInt64Array(t, va, precisionBits, MarshalTypeNearestDelta)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify nearest delta2 encoding.
|
|
|
|
va = va[:0]
|
|
|
|
v = 0
|
|
|
|
for i := 0; i < 8*1024; i++ {
|
2023-01-24 03:41:07 +01:00
|
|
|
v += 30e6 + int64(r.NormFloat64()*1e6)
|
2019-07-23 18:26:39 +02:00
|
|
|
va = append(va, v)
|
|
|
|
}
|
|
|
|
for precisionBits := uint8(1); precisionBits < 15; precisionBits++ {
|
|
|
|
testMarshalUnmarshalInt64Array(t, va, precisionBits, MarshalTypeZSTDNearestDelta2)
|
|
|
|
}
|
|
|
|
for precisionBits := uint8(24); precisionBits < 65; precisionBits++ {
|
|
|
|
testMarshalUnmarshalInt64Array(t, va, precisionBits, MarshalTypeNearestDelta2)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify nearest delta encoding.
|
|
|
|
va = va[:0]
|
|
|
|
v = 1000
|
|
|
|
for i := 0; i < 6; i++ {
|
2023-01-24 03:41:07 +01:00
|
|
|
v += int64(r.NormFloat64() * 100)
|
2019-07-23 18:26:39 +02:00
|
|
|
va = append(va, v)
|
|
|
|
}
|
|
|
|
for precisionBits := uint8(1); precisionBits < 65; precisionBits++ {
|
|
|
|
testMarshalUnmarshalInt64Array(t, va, precisionBits, MarshalTypeNearestDelta)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify nearest delta2 encoding.
|
|
|
|
va = va[:0]
|
|
|
|
v = 0
|
|
|
|
for i := 0; i < 6; i++ {
|
2023-01-24 03:41:07 +01:00
|
|
|
v += 3000 + int64(r.NormFloat64()*100)
|
2019-07-23 18:26:39 +02:00
|
|
|
va = append(va, v)
|
|
|
|
}
|
|
|
|
for precisionBits := uint8(5); precisionBits < 65; precisionBits++ {
|
|
|
|
testMarshalUnmarshalInt64Array(t, va, precisionBits, MarshalTypeNearestDelta2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMarshalInt64ArraySize(t *testing.T) {
|
2023-01-24 03:41:07 +01:00
|
|
|
r := rand.New(rand.NewSource(1))
|
|
|
|
|
2019-07-23 18:26:39 +02:00
|
|
|
var va []int64
|
2023-01-24 03:41:07 +01:00
|
|
|
v := int64(r.Float64() * 1e9)
|
2019-07-23 18:26:39 +02:00
|
|
|
for i := 0; i < 8*1024; i++ {
|
|
|
|
va = append(va, v)
|
2023-01-24 03:41:07 +01:00
|
|
|
v += 30e3 + int64(r.NormFloat64()*1e3)
|
2019-07-23 18:26:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
testMarshalInt64ArraySize(t, va, 1, 500, 1700)
|
|
|
|
testMarshalInt64ArraySize(t, va, 2, 600, 1800)
|
|
|
|
testMarshalInt64ArraySize(t, va, 3, 900, 2100)
|
|
|
|
testMarshalInt64ArraySize(t, va, 4, 1300, 2200)
|
|
|
|
testMarshalInt64ArraySize(t, va, 5, 2000, 3300)
|
|
|
|
testMarshalInt64ArraySize(t, va, 6, 3000, 5000)
|
|
|
|
testMarshalInt64ArraySize(t, va, 7, 4000, 6500)
|
|
|
|
testMarshalInt64ArraySize(t, va, 8, 6000, 8000)
|
|
|
|
testMarshalInt64ArraySize(t, va, 9, 7000, 8800)
|
|
|
|
testMarshalInt64ArraySize(t, va, 10, 8000, 17000)
|
|
|
|
}
|