]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: use SetBytes in UnmarshalReuse benchmark
authorDaniel Martí <mvdan@mvdan.cc>
Fri, 5 Apr 2019 20:28:31 +0000 (22:28 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 5 Apr 2019 20:54:50 +0000 (20:54 +0000)
This was the only benchmark missing the SetBytes call, as spotted
earlier by Bryan.

It's not required to make the benchmark useful, but it can still be a
good way to see how its speed is affected by the reduced allocations:

name                  time/op
CodeUnmarshal-8        12.1ms ± 1%
CodeUnmarshalReuse-8   11.4ms ± 1%

name                  speed
CodeUnmarshal-8       161MB/s ± 1%
CodeUnmarshalReuse-8  171MB/s ± 1%

name                  alloc/op
CodeUnmarshal-8        3.28MB ± 0%
CodeUnmarshalReuse-8   1.94MB ± 0%

name                  allocs/op
CodeUnmarshal-8         92.7k ± 0%
CodeUnmarshalReuse-8    77.6k ± 0%

While at it, remove some unnecessary empty lines.

Change-Id: Ib2bd92d5b3237b8f3092e8c6f863dab548fee2f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/170938
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/encoding/json/bench_test.go
src/encoding/json/example_test.go
src/encoding/json/stream_test.go

index c81ab8e9935f483bc424f6d2481f84f7e907ae57..f2592e3dbdf55f04b41006ea9c3272bd3b52d2a6 100644 (file)
@@ -242,7 +242,7 @@ func BenchmarkCodeUnmarshalReuse(b *testing.B) {
                        }
                }
        })
-       // TODO(bcmills): Is there a missing b.SetBytes here?
+       b.SetBytes(int64(len(codeJSON)))
 }
 
 func BenchmarkUnmarshalString(b *testing.B) {
index 4c075ddaa655f5e6de3119687daa117b24708672..2088c3429749d3477f4dbde5540d79cf857952ee 100644 (file)
@@ -170,7 +170,6 @@ func ExampleDecoder_Decode_stream() {
        // Sam: Go fmt who?
        // Ed: Go fmt yourself!
        // json.Delim: ]
-
 }
 
 // This example uses RawMessage to delay parsing part of a JSON message.
index 8dc74e54669f2cf1e97e973fd3657d1a6d0e1511..1d1999da251c43c34a809767285857cffa9092fe 100644 (file)
@@ -368,7 +368,6 @@ var tokenStreamCases = []tokenStreamCase{
 }
 
 func TestDecodeInStream(t *testing.T) {
-
        for ci, tcase := range tokenStreamCases {
 
                dec := NewDecoder(strings.NewReader(tcase.json))
@@ -401,7 +400,6 @@ func TestDecodeInStream(t *testing.T) {
                        }
                }
        }
-
 }
 
 // Test from golang.org/issue/11893