mirror of
https://github.com/json-iterator/go.git
synced 2025-06-06 22:36:25 +02:00
commit
dcc91365ee
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with stdlib: %v", err)
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
jbIter, err := jsoniter.Marshal(before)
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to marshal with jsoniter: %v", err)
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func Test_Roundtrip(t *testing.T) {
|
|||||||
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
}
|
}
|
||||||
var afterIter T
|
var afterIter T
|
||||||
err = jsoniter.Unmarshal(jbIter, &afterIter)
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func indent(src []byte, prefix string) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStandardMarshal(t *testing.B) {
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
@ -77,68 +77,63 @@ func BenchmarkStandardMarshal(t *testing.B) {
|
|||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
fz.Fuzz(&obj)
|
fz.Fuzz(&obj)
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
jb, err := json.Marshal(obj)
|
jb, err := fn(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
}
|
}
|
||||||
_ = jb
|
_ = jb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStandardUnmarshal(t *testing.B) {
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var before T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&before)
|
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
var after T
|
|
||||||
err = json.Unmarshal(jb, &after)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterMarshal(t *testing.B) {
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
t.ResetTimer()
|
|
||||||
|
|
||||||
var obj T
|
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
|
||||||
fz.Fuzz(&obj)
|
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
jb, err := jsoniter.Marshal(obj)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to marshal:\n input: %s\n error: %v", dump(obj), err)
|
|
||||||
}
|
|
||||||
_ = jb
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJSONIterUnmarshal(t *testing.B) {
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
t.ReportAllocs()
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
t.ResetTimer()
|
}
|
||||||
|
|
||||||
var before T
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
fz.Fuzz(&before)
|
}
|
||||||
jb, err := json.Marshal(before)
|
|
||||||
if err != nil {
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
t.Fatalf("failed to marshal: %v", err)
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
var after T
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
err = jsoniter.Unmarshal(jb, &after)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to unmarshal:\n input: %q\n error: %v", string(jb), err)
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
}
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
139
output_tests/slices/builtins/bool/json_test.go
Normal file
139
output_tests/slices/builtins/bool/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/builtins/bool/types.go
Normal file
3
output_tests/slices/builtins/bool/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []bool
|
139
output_tests/slices/builtins/byte/json_test.go
Normal file
139
output_tests/slices/builtins/byte/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/builtins/byte/types.go
Normal file
3
output_tests/slices/builtins/byte/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []byte
|
139
output_tests/slices/builtins/float32/json_test.go
Normal file
139
output_tests/slices/builtins/float32/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/builtins/float32/types.go
Normal file
3
output_tests/slices/builtins/float32/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []float32
|
139
output_tests/slices/builtins/float64/json_test.go
Normal file
139
output_tests/slices/builtins/float64/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/builtins/float64/types.go
Normal file
3
output_tests/slices/builtins/float64/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []float64
|
139
output_tests/slices/builtins/int32/json_test.go
Normal file
139
output_tests/slices/builtins/int32/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/builtins/int32/types.go
Normal file
3
output_tests/slices/builtins/int32/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []int32
|
139
output_tests/slices/builtins/int8/json_test.go
Normal file
139
output_tests/slices/builtins/int8/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/builtins/int8/types.go
Normal file
3
output_tests/slices/builtins/int8/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []int8
|
139
output_tests/slices/builtins/string/json_test.go
Normal file
139
output_tests/slices/builtins/string/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/builtins/string/types.go
Normal file
3
output_tests/slices/builtins/string/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []string
|
139
output_tests/slices/builtins/uint8/json_test.go
Normal file
139
output_tests/slices/builtins/uint8/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/builtins/uint8/types.go
Normal file
3
output_tests/slices/builtins/uint8/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []uint8
|
139
output_tests/slices/pointers/bool/json_test.go
Normal file
139
output_tests/slices/pointers/bool/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/pointers/bool/types.go
Normal file
3
output_tests/slices/pointers/bool/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []*bool
|
139
output_tests/slices/pointers/float32/json_test.go
Normal file
139
output_tests/slices/pointers/float32/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/pointers/float32/types.go
Normal file
3
output_tests/slices/pointers/float32/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []*float32
|
139
output_tests/slices/pointers/float64/json_test.go
Normal file
139
output_tests/slices/pointers/float64/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/pointers/float64/types.go
Normal file
3
output_tests/slices/pointers/float64/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []*float64
|
139
output_tests/slices/pointers/int32/json_test.go
Normal file
139
output_tests/slices/pointers/int32/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/pointers/int32/types.go
Normal file
3
output_tests/slices/pointers/int32/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []*int32
|
139
output_tests/slices/pointers/int8/json_test.go
Normal file
139
output_tests/slices/pointers/int8/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
3
output_tests/slices/pointers/int8/types.go
Normal file
3
output_tests/slices/pointers/int8/types.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
type T []*int8
|
139
output_tests/slices/pointers/string/json_test.go
Normal file
139
output_tests/slices/pointers/string/json_test.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Roundtrip(t *testing.T) {
|
||||||
|
fz := fuzz.New().MaxDepth(10).NilChance(0.3)
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
var before T
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
|
||||||
|
jbStd, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if string(jbStd) != string(jbIter) {
|
||||||
|
t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s",
|
||||||
|
indent(jbStd, " "), indent(jbIter, " "), dump(before))
|
||||||
|
}
|
||||||
|
|
||||||
|
var afterStd T
|
||||||
|
err = json.Unmarshal(jbIter, &afterStd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with stdlib: %v", err)
|
||||||
|
}
|
||||||
|
var afterIter T
|
||||||
|
err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal with jsoniter: %v", err)
|
||||||
|
}
|
||||||
|
if fingerprint(afterStd) != fingerprint(afterIter) {
|
||||||
|
t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s",
|
||||||
|
dump(afterStd), dump(afterIter), indent(jbIter, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const indentStr = "> "
|
||||||
|
|
||||||
|
func fingerprint(obj interface{}) string {
|
||||||
|
c := spew.ConfigState{
|
||||||
|
SortKeys: true,
|
||||||
|
SpewKeys: true,
|
||||||
|
}
|
||||||
|
return c.Sprintf("%v", obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dump(obj interface{}) string {
|
||||||
|
cfg := spew.ConfigState{
|
||||||
|
Indent: indentStr,
|
||||||
|
}
|
||||||
|
return cfg.Sdump(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indent(src []byte, prefix string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
json.Indent(&buf, src, prefix, indentStr)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var obj T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&obj)
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
jb, err := fn(obj)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err)
|
||||||
|
}
|
||||||
|
_ = jb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) {
|
||||||
|
t.ReportAllocs()
|
||||||
|
t.ResetTimer()
|
||||||
|
|
||||||
|
var before T
|
||||||
|
fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3)
|
||||||
|
fz.Fuzz(&before)
|
||||||
|
jb, err := json.Marshal(before)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
var after T
|
||||||
|
err = fn(jb, &after)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardMarshal(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "stdlib", json.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStandardUnmarshal(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "stdlib", json.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalFastest(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalFastest(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalDefault(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalDefault(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterMarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) {
|
||||||
|
benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user