<commit_before>package benchmark_test

import (
	"compress/gzip"
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"
)

var bench_inputs = []string{
	// from https://gist.githubusercontent.com/feeeper/2197d6d734729625a037af1df14cf2aa/raw/2f22b120e476d897179be3c1e2483d18067aa7df/config.toml
	"config",

	// converted from https://github.com/miloyip/nativejson-benchmark
	"canada",
	"citm_catalog",
	"twitter",
	"code",

	// converted from https://raw.githubusercontent.com/mailru/easyjson/master/benchmark/example.json
	"example",
}

func BenchmarkUnmarshalDataset(b *testing.B) {
	for _, tc := range bench_inputs {
		buf := fixture(b, tc)
		b.Run(tc, func(b *testing.B) {
			bench(b, func(r runner, b *testing.B) {
				if r.name == "bs" && tc == "canada" {
					// bs can't handle the canada dataset due to mixed integer &
					// floats values in an array.
					b.Skip()
				}

				b.SetBytes(int64(len(buf)))
				b.ReportAllocs()
				b.ResetTimer()
				for i := 0; i < b.N; i++ {
					var v interface{}
					check(b, r.unmarshal(buf, &v))
				}
			})<commit_msg>Add sanity check tests to benchmark dataset (#497)<commit_after>package benchmark_test

import (
	"compress/gzip"
	"encoding/json"
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"

	"github.com/stretchr/testify/require"
)

var bench_inputs = []struct {
	name    string
	jsonLen int
}{
	// from https://gist.githubusercontent.com/feeeper/2197d6d734729625a037af1df14cf2aa/raw/2f22b120e476d897179be3c1e2483d18067aa7df/config.toml
	{"config", 806507},

	// converted from https://github.com/miloyip/nativejson-benchmark
	{"canada", 2090234},
	{"citm_catalog", 479897},
	{"twitter", 428778},
	{"code", 1940472},

	// converted from https://raw.githubusercontent.com/mailru/easyjson/master/benchmark/example.json
	{"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) {
	for _, tc := range bench_inputs {
		buf := fixture(b, tc.name)
		b.Run(tc.name, func(b *testing.B) {
			bench(b, func(r runner, b *testing.B) {
				if r.name == "bs" && tc.name == "canada" {
					b.Skip("skipping: burntsushi can't handle mixed arrays")
				}

				b.SetBytes(int64(len(buf)))
				b.ReportAllocs()
				b.ResetTimer()
				for i := 0; i < b.N; i++ {
					var v interface{}
					check(b, r.unmarshal(buf, &v))
				}
			})
{'fraction_non_alphanumeric': 0.1627069834413247, 'fraction_numerical': 0.05075593952483801, 'mean_word_length': 3.3832807570977916, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5915053', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1090, 'n_words': 212}