Skip to content
9 changes: 0 additions & 9 deletions cmd/strucmd/main.go

This file was deleted.

360 changes: 332 additions & 28 deletions dynamicstruct/decoder/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,310 @@ import (
. "github.com/goldeneggg/structil/dynamicstruct/decoder"
)

var (
singleJSON = []byte(`
{
"null_field":null,
"string_field":"かきくけこ",
"int_field":45678,
"float64_field":9.876,
"bool_field":false,
"struct_ptr_field":{
"key":"hugakey",
"value":"hugavalue"
},
"array_string_field":[
"array_str_1",
"array_str_2"
],
"array_struct_field":[
{
"kkk":"kkk1",
"vvvv":"vvv1"
},
{
"kkk":"kkk2",
"vvvv":"vvv2"
},
{
"kkk":"kkk3",
"vvvv":"vvv3"
}
]
}
`)

arrayJSON = []byte(`
[
{
"null_field":null,
"string_field":"かきくけこ",
"int_field":45678,
"float64_field":9.876,
"bool_field":false,
"struct_ptr_field":{
"key":"hugakey",
"value":"hugavalue"
},
"array_string_field":[
"array_str_1",
"array_str_2"
],
"array_struct_field":[
{
"kkk":"kkk1",
"vvvv":"vvv1"
},
{
"kkk":"kkk2",
"vvvv":"vvv2"
},
{
"kkk":"kkk3",
"vvvv":"vvv3"
}
]
},
{
"null_field":null,
"string_field":"さしすせそ",
"int_field":7890,
"float64_field":4.99,
"bool_field":true,
"struct_ptr_field":{
"key":"hugakeyXXX",
"value":"hugavalueXXX"
},
"array_string_field":[
"array_str_111",
"array_str_222"
],
"array_struct_field":[
{
"kkk":"kkk99",
"vvvv":"vvv99"
},
{
"kkk":"kkk999",
"vvvv":"vvv999"
},
{
"kkk":"kkk9999",
"vvvv":"vvv9999"
}
]
}
]
`)

singleYAML = []byte(`
null_field: null
string_field: かきくけこ
int_field: 45678
float64_field: 9.876
bool_field: false
struct_ptr_field:
key: hugakey
value: hugavalue
array_string_field:
- array_str_1
- array_str_2
array_struct_field:
- kkk: kkk1
vvvv: vvv1
- kkk: kkk2
vvvv: vvv2
- kkk: kkk3
vvvv: vvv3
`)

arrayYAML = []byte(`
- null_field: null
string_field: かきくけこ
int_field: 45678
float64_field: 9.876
bool_field: false
struct_ptr_field:
key: hugakey
value: hugavalue
array_string_field:
- array_str_1
- array_str_2
array_struct_field:
- kkk: kkk1
vvvv: vvv1
- kkk: kkk2
vvvv: vvv2
- kkk: kkk3
vvvv: vvv3
- null_field: null
string_field: さしすせそ
int_field: 7890
float64_field: 4.99
bool_field: true
struct_ptr_field:
key: hugakeyXXX
value: hugavalueXXX
array_string_field:
- array_str_111
- array_str_222
array_struct_field:
- kkk: kkk99
vvvv: vvv99
- kkk: kkk999
vvvv: vvv999
- kkk: kkk9999
vvvv: vvv9999
`)

//lint:ignore U1000 It's ok because this is for the future.
singleTOML = []byte(`
string_field = "かきくけこ,"
int_field = 45678
float64_field = "9.876,"
bool_field = false
array_string_field = ["array_str_1", "array_str_2"]

[struct_ptr_field]
key = "hugakey"
value = "hugavalue"

[[array_struct_field]]
kkk = "kkk1"
vvvv = "vvv1"

[[array_struct_field]]
kkk = "kkk2"
vvvv = "vvv2"

[[array_struct_field]]
kkk = "kkk3"
vvvv = "vvv3"
`)

//lint:ignore U1000 It's ok because this is for the future.
singleXML = []byte(`
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<null_field/>
<string_field>かきくけこ</string_field>
<int_field>45678</int_field>
<float64_field>9.876</float64_field>
<bool_field>false</bool_field>
<struct_ptr_field>
<key>hugakey</key>
<value>hugavalue</value>
</struct_ptr_field>
<array_string_field>array_str_1</array_string_field>
<array_string_field>array_str_2</array_string_field>
<array_struct_field>
<kkk>kkk1</kkk>
<vvvv>vvv1</vvvv>
</array_struct_field>
<array_struct_field>
<kkk>kkk2</kkk>
<vvvv>vvv2</vvvv>
</array_struct_field>
<array_struct_field>
<kkk>kkk3</kkk>
<vvvv>vvv3</vvvv>
</array_struct_field>
</root>
`)

//lint:ignore U1000 It's ok because this is for the future.
arrayXML = []byte(`
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<0>
<null_field/>
<string_field>かきくけこ</string_field>
<int_field>45678</int_field>
<float64_field>9.876</float64_field>
<bool_field>false</bool_field>
<struct_ptr_field>
<key>hugakey</key>
<value>hugavalue</value>
</struct_ptr_field>
<array_string_field>array_str_1</array_string_field>
<array_string_field>array_str_2</array_string_field>
<array_struct_field>
<kkk>kkk1</kkk>
<vvvv>vvv1</vvvv>
</array_struct_field>
<array_struct_field>
<kkk>kkk2</kkk>
<vvvv>vvv2</vvvv>
</array_struct_field>
<array_struct_field>
<kkk>kkk3</kkk>
<vvvv>vvv3</vvvv>
</array_struct_field>
</0>
<1>
<null_field/>
<string_field>さしすせそ</string_field>
<int_field>7890</int_field>
<float64_field>4.99</float64_field>
<bool_field>true</bool_field>
<struct_ptr_field>
<key>hugakeyXXX</key>
<value>hugavalueXXX</value>
</struct_ptr_field>
<array_string_field>array_str_111</array_string_field>
<array_string_field>array_str_222</array_string_field>
<array_struct_field>
<kkk>kkk99</kkk>
<vvvv>vvv99</vvvv>
</array_struct_field>
<array_struct_field>
<kkk>kkk999</kkk>
<vvvv>vvv999</vvvv>
</array_struct_field>
<array_struct_field>
<kkk>kkk9999</kkk>
<vvvv>vvv9999</vvvv>
</array_struct_field>
</1>
</root>
`)

//lint:ignore U1000 It's ok because this is for the future.
singleHCL = []byte(`
null_field =

string_field = "かきくけこ,"

int_field = 45678

float64_field = "9.876,"

bool_field = false

struct_ptr_field = {
key = "hugakey"
value = "hugavalue"
}

array_string_field = ["array_str_1", "array_str_2"]

array_struct_field = {
kkk = "kkk1"
vvvv = "vvv1"
}

"array_struct_field" = {
kkk = "kkk2"
vvvv = "vvv2"
}

array_struct_field = {
kkk = "kkk3"
vvvv = "vvv3"
}
`)
)

func BenchmarkFromJSON_singleJSON(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down Expand Up @@ -74,6 +378,34 @@ func BenchmarkDynamicStruct_arrayJSON_nest_useTag(b *testing.B) {
}
}

func BenchmarkJSONToGetter_singleJSON_nonNest(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = JSONToGetter(singleJSON, false)
}
}

func BenchmarkJSONToGetter_singleJSON_nest(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = JSONToGetter(singleJSON, true)
}
}

func BenchmarkJSONToGetter_arrayJSON_nonNest(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = JSONToGetter(arrayJSON, false)
}
}

func BenchmarkJSONToGetter_arrayJSON_nest(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = JSONToGetter(arrayJSON, true)
}
}

func BenchmarkFromYAML_singleYAML(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down Expand Up @@ -142,34 +474,6 @@ func BenchmarkDynamicStruct_arrayYAML_nest_useTag(b *testing.B) {
}
}

func BenchmarkJSONToGetter_singleJSON_nonNest(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = JSONToGetter(singleJSON, false)
}
}

func BenchmarkJSONToGetter_singleJSON_nest(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = JSONToGetter(singleJSON, true)
}
}

func BenchmarkJSONToGetter_arrayJSON_nonNest(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = JSONToGetter(arrayJSON, false)
}
}

func BenchmarkJSONToGetter_arrayJSON_nest(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = JSONToGetter(arrayJSON, true)
}
}

func BenchmarkYAMLToGetter_singleYAML_nonNest(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down
Loading