840df4a229
name old time/op new time/op delta UnmarshalDataset/config-32 81.2ms ± 3% 77.8ms ± 3% -4.25% (p=0.000 n=20+19) UnmarshalDataset/canada-32 104ms ± 5% 105ms ± 4% ~ (p=0.102 n=20+20) UnmarshalDataset/citm_catalog-32 57.5ms ± 5% 59.0ms ± 5% +2.54% (p=0.033 n=20+20) UnmarshalDataset/twitter-32 25.7ms ± 7% 28.1ms ± 5% +9.33% (p=0.000 n=20+20) UnmarshalDataset/code-32 305ms ± 6% 292ms ± 5% -4.29% (p=0.000 n=20+19) UnmarshalDataset/example-32 519µs ± 6% 522µs ± 5% ~ (p=0.659 n=20+20) UnmarshalSimple/struct-32 1.44µs ± 1% 1.17µs ± 6% -18.78% (p=0.000 n=14+20) UnmarshalSimple/map-32 2.30µs ± 4% 1.99µs ± 4% -13.65% (p=0.000 n=20+19) ReferenceFile/struct-32 44.1µs ± 4% 38.1µs ± 5% -13.61% (p=0.000 n=18+20) ReferenceFile/map-32 197µs ± 7% 189µs ± 5% -3.91% (p=0.000 n=20+20) HugoFrontMatter-32 45.9µs ± 6% 39.3µs ± 6% -14.46% (p=0.000 n=19+20) name old speed new speed delta UnmarshalDataset/config-32 12.9MB/s ± 3% 13.5MB/s ± 3% +4.42% (p=0.000 n=20+19) UnmarshalDataset/canada-32 21.1MB/s ± 5% 20.9MB/s ± 4% ~ (p=0.101 n=20+20) UnmarshalDataset/citm_catalog-32 9.72MB/s ± 6% 9.47MB/s ± 5% -2.53% (p=0.031 n=20+20) UnmarshalDataset/twitter-32 17.2MB/s ± 7% 15.8MB/s ± 5% -8.57% (p=0.000 n=20+20) UnmarshalDataset/code-32 8.81MB/s ± 7% 9.20MB/s ± 5% +4.47% (p=0.000 n=20+19) UnmarshalDataset/example-32 15.6MB/s ± 6% 15.5MB/s ± 5% ~ (p=0.644 n=20+20) UnmarshalSimple/struct-32 7.61MB/s ± 1% 9.39MB/s ± 7% +23.33% (p=0.000 n=15+20) UnmarshalSimple/map-32 4.78MB/s ± 4% 5.54MB/s ± 5% +15.85% (p=0.000 n=20+19) ReferenceFile/struct-32 119MB/s ± 4% 138MB/s ± 5% +15.79% (p=0.000 n=18+20) ReferenceFile/map-32 26.6MB/s ± 7% 27.7MB/s ± 5% +4.06% (p=0.000 n=20+20) HugoFrontMatter-32 11.9MB/s ± 6% 13.9MB/s ± 6% +16.91% (p=0.000 n=19+20) name old alloc/op new alloc/op delta UnmarshalDataset/config-32 16.9MB ± 0% 13.9MB ± 0% -17.48% (p=0.000 n=18+18) UnmarshalDataset/canada-32 74.3MB ± 0% 74.3MB ± 0% -0.00% (p=0.000 n=20+20) UnmarshalDataset/citm_catalog-32 37.3MB ± 0% 37.3MB ± 0% +0.11% (p=0.000 n=20+20) UnmarshalDataset/twitter-32 15.6MB ± 0% 15.6MB ± 0% ~ (p=0.211 n=19+20) UnmarshalDataset/code-32 59.5MB ± 0% 52.4MB ± 0% -11.96% (p=0.000 n=19+20) UnmarshalDataset/example-32 238kB ± 0% 239kB ± 0% +0.02% (p=0.000 n=18+20) UnmarshalSimple/struct-32 981B ± 0% 709B ± 0% -27.73% (p=0.000 n=20+20) UnmarshalSimple/map-32 1.45kB ± 0% 1.17kB ± 0% -18.82% (p=0.000 n=20+20) ReferenceFile/struct-32 11.8kB ± 0% 9.7kB ± 0% -17.64% (p=0.000 n=20+20) ReferenceFile/map-32 51.5kB ± 0% 52.2kB ± 0% +1.30% (p=0.000 n=20+17) HugoFrontMatter-32 12.1kB ± 0% 11.1kB ± 0% -7.97% (p=0.000 n=20+19) name old allocs/op new allocs/op delta UnmarshalDataset/config-32 645k ± 0% 557k ± 0% -13.76% (p=0.000 n=20+16) UnmarshalDataset/canada-32 896k ± 0% 896k ± 0% -0.00% (p=0.000 n=20+20) UnmarshalDataset/citm_catalog-32 380k ± 0% 377k ± 0% -0.75% (p=0.000 n=19+20) UnmarshalDataset/twitter-32 158k ± 0% 158k ± 0% -0.01% (p=0.000 n=18+18) UnmarshalDataset/code-32 2.92M ± 0% 2.57M ± 0% -11.87% (p=0.000 n=20+20) UnmarshalDataset/example-32 3.66k ± 0% 3.64k ± 0% -0.63% (p=0.000 n=20+20) UnmarshalSimple/struct-32 13.0 ± 0% 10.0 ± 0% -23.08% (p=0.000 n=20+20) UnmarshalSimple/map-32 22.0 ± 0% 19.0 ± 0% -13.64% (p=0.000 n=20+20) ReferenceFile/struct-32 253 ± 0% 155 ± 0% -38.74% (p=0.000 n=20+20) ReferenceFile/map-32 1.67k ± 0% 1.44k ± 0% -14.23% (p=0.000 n=20+20) HugoFrontMatter-32 357 ± 0% 313 ± 0% -12.32% (p=0.000 n=20+20)
228 lines
3.8 KiB
Go
228 lines
3.8 KiB
Go
package benchmark_test
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/pelletier/go-toml/v2"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func BenchmarkUnmarshalSimple(b *testing.B) {
|
|
doc := []byte(`A = "hello"`)
|
|
|
|
b.Run("struct", func(b *testing.B) {
|
|
b.SetBytes(int64(len(doc)))
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
d := struct {
|
|
A string
|
|
}{}
|
|
|
|
err := toml.Unmarshal(doc, &d)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
})
|
|
|
|
b.Run("map", func(b *testing.B) {
|
|
b.SetBytes(int64(len(doc)))
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
d := map[string]interface{}{}
|
|
err := toml.Unmarshal(doc, &d)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
type benchmarkDoc struct {
|
|
Table struct {
|
|
Key string
|
|
Subtable struct {
|
|
Key string
|
|
}
|
|
Inline struct {
|
|
Name struct {
|
|
First string
|
|
Last string
|
|
}
|
|
Point struct {
|
|
X int64
|
|
U int64
|
|
}
|
|
}
|
|
}
|
|
String struct {
|
|
Basic struct {
|
|
Basic string
|
|
}
|
|
Multiline struct {
|
|
Key1 string
|
|
Key2 string
|
|
Key3 string
|
|
Continued struct {
|
|
Key1 string
|
|
Key2 string
|
|
Key3 string
|
|
}
|
|
}
|
|
Literal struct {
|
|
Winpath string
|
|
Winpath2 string
|
|
Quoted string
|
|
Regex string
|
|
Multiline struct {
|
|
Regex2 string
|
|
Lines string
|
|
}
|
|
}
|
|
}
|
|
Integer struct {
|
|
Key1 int64
|
|
Key2 int64
|
|
Key3 int64
|
|
Key4 int64
|
|
Underscores struct {
|
|
Key1 int64
|
|
Key2 int64
|
|
Key3 int64
|
|
}
|
|
}
|
|
Float struct {
|
|
Fractional struct {
|
|
Key1 float64
|
|
Key2 float64
|
|
Key3 float64
|
|
}
|
|
Exponent struct {
|
|
Key1 float64
|
|
Key2 float64
|
|
Key3 float64
|
|
}
|
|
Both struct {
|
|
Key float64
|
|
}
|
|
Underscores struct {
|
|
Key1 float64
|
|
Key2 float64
|
|
}
|
|
}
|
|
Boolean struct {
|
|
True bool
|
|
False bool
|
|
}
|
|
Datetime struct {
|
|
Key1 time.Time
|
|
Key2 time.Time
|
|
Key3 time.Time
|
|
}
|
|
Array struct {
|
|
Key1 []int64
|
|
Key2 []string
|
|
Key3 [][]int64
|
|
// TODO: Key4 not supported by go-toml's Unmarshal
|
|
Key5 []int64
|
|
Key6 []int64
|
|
}
|
|
Products []struct {
|
|
Name string
|
|
Sku int64
|
|
Color string
|
|
}
|
|
Fruit []struct {
|
|
Name string
|
|
Physical struct {
|
|
Color string
|
|
Shape string
|
|
Variety []struct {
|
|
Name string
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkReferenceFile(b *testing.B) {
|
|
bytes, err := ioutil.ReadFile("benchmark.toml")
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
|
|
b.Run("struct", func(b *testing.B) {
|
|
b.SetBytes(int64(len(bytes)))
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
d := benchmarkDoc{}
|
|
err := toml.Unmarshal(bytes, &d)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
})
|
|
|
|
b.Run("map", func(b *testing.B) {
|
|
b.SetBytes(int64(len(bytes)))
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
d := map[string]interface{}{}
|
|
err := toml.Unmarshal(bytes, &d)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestReferenceFile(t *testing.T) {
|
|
bytes, err := ioutil.ReadFile("benchmark.toml")
|
|
require.NoError(t, err)
|
|
d := benchmarkDoc{}
|
|
err = toml.Unmarshal(bytes, &d)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func BenchmarkHugoFrontMatter(b *testing.B) {
|
|
bytes := []byte(`
|
|
categories = ["Development", "VIM"]
|
|
date = "2012-04-06"
|
|
description = "spf13-vim is a cross platform distribution of vim plugins and resources for Vim."
|
|
slug = "spf13-vim-3-0-release-and-new-website"
|
|
tags = [".vimrc", "plugins", "spf13-vim", "vim"]
|
|
title = "spf13-vim 3.0 release and new website"
|
|
include_toc = true
|
|
show_comments = false
|
|
|
|
[[cascade]]
|
|
background = "yosemite.jpg"
|
|
[cascade._target]
|
|
kind = "page"
|
|
lang = "en"
|
|
path = "/blog/**"
|
|
|
|
[[cascade]]
|
|
background = "goldenbridge.jpg"
|
|
[cascade._target]
|
|
kind = "section"
|
|
`)
|
|
b.SetBytes(int64(len(bytes)))
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
d := map[string]interface{}{}
|
|
err := toml.Unmarshal(bytes, &d)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|