mirror of
https://github.com/json-iterator/go.git
synced 2025-04-23 11:37:32 +02:00
Adapt tests to use new Config structs
the unit test uses compatible mode. The benchmarks measure compat, default, and fastest. This still fails for strings and slices and maps all over the place.
This commit is contained in:
parent
5d3508979f
commit
8f3de9c412
@ -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)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user