]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/xml: parallelize benchmarks
authorBryan C. Mills <bcmills@google.com>
Fri, 10 Feb 2017 20:54:35 +0000 (15:54 -0500)
committerBryan Mills <bcmills@google.com>
Wed, 26 Apr 2017 19:04:03 +0000 (19:04 +0000)
Results remain comparable with the non-parallel version with -cpu=1:
benchmark                old ns/op     new ns/op     delta
BenchmarkMarshal         31220         28618         -8.33%
BenchmarkMarshal-6       37181         7658          -79.40%
BenchmarkUnmarshal       81837         83522         +2.06%
BenchmarkUnmarshal-6     96339         18244         -81.06%

benchmark                old allocs     new allocs     delta
BenchmarkMarshal         23             23             +0.00%
BenchmarkMarshal-6       23             23             +0.00%
BenchmarkUnmarshal       189            189            +0.00%
BenchmarkUnmarshal-6     189            189            +0.00%

benchmark                old bytes     new bytes     delta
BenchmarkMarshal         5776          5776          +0.00%
BenchmarkMarshal-6       5776          5776          +0.00%
BenchmarkUnmarshal       8576          8576          +0.00%
BenchmarkUnmarshal-6     8576          8576          +0.00%

updates #18177

Change-Id: I7e7055a11d18896bd54d7d773f2ec64767cdb4c8
Reviewed-on: https://go-review.googlesource.com/36810
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/encoding/xml/marshal_test.go

index 4fb901f258a9a2802250cdcf5e6e8533d68e796a..674c6b5b3f4de3a401613babb8260738ec1c7234 100644 (file)
@@ -1901,17 +1901,21 @@ func TestMarshalFlush(t *testing.T) {
 
 func BenchmarkMarshal(b *testing.B) {
        b.ReportAllocs()
-       for i := 0; i < b.N; i++ {
-               Marshal(atomValue)
-       }
+       b.RunParallel(func(pb *testing.PB) {
+               for pb.Next() {
+                       Marshal(atomValue)
+               }
+       })
 }
 
 func BenchmarkUnmarshal(b *testing.B) {
        b.ReportAllocs()
        xml := []byte(atomXml)
-       for i := 0; i < b.N; i++ {
-               Unmarshal(xml, &Feed{})
-       }
+       b.RunParallel(func(pb *testing.PB) {
+               for pb.Next() {
+                       Unmarshal(xml, &Feed{})
+               }
+       })
 }
 
 // golang.org/issue/6556