Add sanity check tests to benchmark dataset (#497)
Marshal results into JSON and ensure all runners match
This commit is contained in:
@@ -2,35 +2,61 @@ package benchmark_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var bench_inputs = []string{
|
var bench_inputs = []struct {
|
||||||
|
name string
|
||||||
|
jsonLen int
|
||||||
|
}{
|
||||||
// from https://gist.githubusercontent.com/feeeper/2197d6d734729625a037af1df14cf2aa/raw/2f22b120e476d897179be3c1e2483d18067aa7df/config.toml
|
// from https://gist.githubusercontent.com/feeeper/2197d6d734729625a037af1df14cf2aa/raw/2f22b120e476d897179be3c1e2483d18067aa7df/config.toml
|
||||||
"config",
|
{"config", 806507},
|
||||||
|
|
||||||
// converted from https://github.com/miloyip/nativejson-benchmark
|
// converted from https://github.com/miloyip/nativejson-benchmark
|
||||||
"canada",
|
{"canada", 2090234},
|
||||||
"citm_catalog",
|
{"citm_catalog", 479897},
|
||||||
"twitter",
|
{"twitter", 428778},
|
||||||
"code",
|
{"code", 1940472},
|
||||||
|
|
||||||
// converted from https://raw.githubusercontent.com/mailru/easyjson/master/benchmark/example.json
|
// converted from https://raw.githubusercontent.com/mailru/easyjson/master/benchmark/example.json
|
||||||
"example",
|
{"example", 7779},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalDatasetCode(t *testing.T) {
|
||||||
|
for _, tc := range bench_inputs {
|
||||||
|
buf := fixture(t, tc.name)
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
for _, r := range runners {
|
||||||
|
if r.name == "bs" && tc.name == "canada" {
|
||||||
|
t.Skip("skipping: burntsushi can't handle mixed arrays")
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run(r.name, func(t *testing.T) {
|
||||||
|
var v interface{}
|
||||||
|
check(t, r.unmarshal(buf, &v))
|
||||||
|
|
||||||
|
b, err := json.Marshal(v)
|
||||||
|
check(t, err)
|
||||||
|
require.Equal(t, len(b), tc.jsonLen)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUnmarshalDataset(b *testing.B) {
|
func BenchmarkUnmarshalDataset(b *testing.B) {
|
||||||
for _, tc := range bench_inputs {
|
for _, tc := range bench_inputs {
|
||||||
buf := fixture(b, tc)
|
buf := fixture(b, tc.name)
|
||||||
b.Run(tc, func(b *testing.B) {
|
b.Run(tc.name, func(b *testing.B) {
|
||||||
bench(b, func(r runner, b *testing.B) {
|
bench(b, func(r runner, b *testing.B) {
|
||||||
if r.name == "bs" && tc == "canada" {
|
if r.name == "bs" && tc.name == "canada" {
|
||||||
// bs can't handle the canada dataset due to mixed integer &
|
b.Skip("skipping: burntsushi can't handle mixed arrays")
|
||||||
// floats values in an array.
|
|
||||||
b.Skip()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
|
|||||||
Reference in New Issue
Block a user