Add additional dataset to benchmarks (#490)
Adding several files to stress test the unmarshaller. Most were converted from JSON so they may not be very realistic use cases. ``` goos: linux goarch: amd64 pkg: github.com/pelletier/go-toml/v2/benchmark cpu: Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz BenchmarkUnmarshalDataset/config/v2-2 16 66339063 ns/op 15.81 MB/s 16850159 B/op 645454 allocs/op BenchmarkUnmarshalDataset/config/v1-2 7 147289186 ns/op 7.12 MB/s 60669811 B/op 870486 allocs/op BenchmarkUnmarshalDataset/config/bs-2 12 88966009 ns/op 11.79 MB/s 29949268 B/op 705573 allocs/op BenchmarkUnmarshalDataset/canada/v2-2 8 145433377 ns/op 15.14 MB/s 74282227 B/op 895641 allocs/op BenchmarkUnmarshalDataset/canada/v1-2 3 434913677 ns/op 5.06 MB/s 138664290 B/op 1897300 allocs/op BenchmarkUnmarshalDataset/citm_catalog/v2-2 19 55256979 ns/op 10.10 MB/s 37122952 B/op 369492 allocs/op BenchmarkUnmarshalDataset/citm_catalog/v1-2 10 110343191 ns/op 5.06 MB/s 54743595 B/op 727704 allocs/op BenchmarkUnmarshalDataset/citm_catalog/bs-2 21 51634081 ns/op 10.81 MB/s 17196872 B/op 325830 allocs/op BenchmarkUnmarshalDataset/twitter/v2-2 50 26660937 ns/op 16.57 MB/s 15580238 B/op 156394 allocs/op BenchmarkUnmarshalDataset/twitter/v1-2 30 43128488 ns/op 10.25 MB/s 21203420 B/op 266110 allocs/op BenchmarkUnmarshalDataset/twitter/bs-2 48 27337976 ns/op 16.16 MB/s 8795405 B/op 145370 allocs/op BenchmarkUnmarshalDataset/code/v2-2 4 276279202 ns/op 9.71 MB/s 59293948 B/op 2907227 allocs/op BenchmarkUnmarshalDataset/code/v1-2 3 421910642 ns/op 6.36 MB/s 161733770 B/op 2478194 allocs/op BenchmarkUnmarshalDataset/code/bs-2 4 323158157 ns/op 8.31 MB/s 133056988 B/op 1439475 allocs/op BenchmarkUnmarshalDataset/example/v2-2 2444 479553 ns/op 16.89 MB/s 237606 B/op 3609 allocs/op BenchmarkUnmarshalDataset/example/v1-2 1321 911995 ns/op 8.88 MB/s 377502 B/op 6133 allocs/op BenchmarkUnmarshalDataset/example/bs-2 1898 555649 ns/op 14.58 MB/s 178485 B/op 3362 allocs/op BenchmarkUnmarshalSimple/v2-2 896760 1200 ns/op BenchmarkUnmarshalSimple/v1-2 207364 6070 ns/op BenchmarkUnmarshalSimple/bs-2 420952 2925 ns/op BenchmarkReferenceFile/v2-2 29473 39433 ns/op 132.93 MB/s 11812 B/op 253 allocs/op BenchmarkReferenceFile/v1-2 2823 361383 ns/op 14.51 MB/s 136470 B/op 2745 allocs/op BenchmarkReferenceFile/bs-2 3097 391116 ns/op 13.40 MB/s 80795 B/op 1729 allocs/op PASS ok github.com/pelletier/go-toml/v2/benchmark 34.255s ```
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
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))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// fixture returns the uncompressed contents of path.
|
||||
func fixture(tb testing.TB, path string) []byte {
|
||||
f, err := os.Open(filepath.Join("testdata", path+".toml.gz"))
|
||||
check(tb, err)
|
||||
defer f.Close()
|
||||
|
||||
gz, err := gzip.NewReader(f)
|
||||
check(tb, err)
|
||||
|
||||
buf, err := ioutil.ReadAll(gz)
|
||||
check(tb, err)
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
func check(tb testing.TB, err error) {
|
||||
if err != nil {
|
||||
tb.Helper()
|
||||
tb.Fatal(err)
|
||||
}
|
||||
}
|
||||
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Reference in New Issue
Block a user