Skip to content

Instantly share code, notes, and snippets.

@bmatsuo
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmatsuo/c4f6b5d5c09881429a32 to your computer and use it in GitHub Desktop.
Save bmatsuo/c4f6b5d5c09881429a32 to your computer and use it in GitHub Desktop.

#Benchmark results created with go test

Test data was generated on a 4-core i7 (16GB ram) Lenovo ThinkPad running Ubuntu 14.04.

Each benchmark was run for 10 seconds (10x the default) to reduce noise seen when the benchmarks ran for 1 second.

go test -run=NONE -bench=Reader -benchtime=10s

I've included the raw test results for each of the master branch, the original pull request, and the pull request modified to avoid heap allocation by inlining the copyWriter struct literal. For the latter two I've included benchcmp output comparing them to the master branch. There is also a comparison between the pull request and it's modified form.

NOTE: The "NoCopy" benchmarks should all be noise because they don't use the WriteTo method.

NOTE: The test output has been passed through column -t for readability. I'm not sure if they will properly run through benchcmp in this form.

##Master branch

Raw go test output:

PASS
BenchmarkReaderManpage            1000000     20223     ns/op  126.09   MB/s
BenchmarkReaderManpage_buffered   1000000     20176     ns/op  126.39   MB/s
BenchmarkReaderManpageNoCopy      1000000     20179     ns/op  126.36   MB/s
BenchmarkReaderJSON               50000       320459    ns/op  76.23    MB/s
BenchmarkReaderJSON_buffered      50000       332016    ns/op  68.00    MB/s
BenchmarkReaderJSONNoCopy         50000       334736    ns/op  67.45    MB/s
BenchmarkReaderRandom             10000       1859415   ns/op  5640.66  MB/s
BenchmarkReaderRandom_buffered    10000       1837270   ns/op  5707.95  MB/s
BenchmarkReaderRandomNoCopy       10000       2782352   ns/op  3769.13  MB/s
BenchmarkReaderConstant           1000        16053094  ns/op  30.88    MB/s
BenchmarkReaderConstant_buffered  1000        16138921  ns/op  30.59    MB/s
BenchmarkReaderConstantNoCopy     1000        16921298  ns/op  29.17    MB/s
ok                                github.com/mreiferson/go-snappystream  246.718s

##Original PR (w/ extra allocation)

Raw go test output:

PASS
BenchmarkReaderManpage            1000000     19525     ns/op  130.60   MB/s
BenchmarkReaderManpage_buffered   1000000     19605     ns/op  130.07   MB/s
BenchmarkReaderManpageNoCopy      1000000     19686     ns/op  129.53   MB/s
BenchmarkReaderJSON               50000       314747    ns/op  77.61    MB/s
BenchmarkReaderJSON_buffered      50000       330732    ns/op  68.27    MB/s
BenchmarkReaderJSONNoCopy         50000       332856    ns/op  67.83    MB/s
BenchmarkReaderRandom             10000       1893232   ns/op  5539.91  MB/s
BenchmarkReaderRandom_buffered    10000       1842477   ns/op  5691.82  MB/s
BenchmarkReaderRandomNoCopy       10000       2765457   ns/op  3792.16  MB/s
BenchmarkReaderConstant           1000        16210969  ns/op  30.58    MB/s
BenchmarkReaderConstant_buffered  1000        16321791  ns/op  30.24    MB/s
BenchmarkReaderConstantNoCopy     1000        16937709  ns/op  29.14    MB/s
ok                                github.com/mreiferson/go-snappystream  245.194s

Difference from "master" created with benchcmp

benchmark                            old ns/op     new ns/op     delta
BenchmarkReaderManpage               20219         19615         -2.99%
BenchmarkReaderManpage_buffered      20150         19615         -2.66%
BenchmarkReaderManpageNoCopy         24238         24093         -0.60%
BenchmarkReaderJSON                  318067        314540        -1.11%
BenchmarkReaderJSON_buffered         329900        322778        -2.16%
BenchmarkReaderJSONNoCopy            383377        372792        -2.76%
BenchmarkReaderRandom                1851622       1847109       -0.24%
BenchmarkReaderRandom_buffered       1842622       1831186       -0.62%
BenchmarkReaderRandomNoCopy          2763322       2737107       -0.95%
BenchmarkReaderConstant              16101400      16250396      +0.93%
BenchmarkReaderConstant_buffered     16059995      16193529      +0.83%
BenchmarkReaderConstantNoCopy        16823845      16849812      +0.15%

benchmark                            old MB/s     new MB/s     speedup
BenchmarkReaderManpage               126.11       130.00       1.03x
BenchmarkReaderManpage_buffered      126.55       130.00       1.03x
BenchmarkReaderManpageNoCopy         105.21       105.84       1.01x
BenchmarkReaderJSON                  76.80        77.66        1.01x
BenchmarkReaderJSON_buffered         68.44        69.95        1.02x
BenchmarkReaderJSONNoCopy            58.89        60.56        1.03x
BenchmarkReaderRandom                5664.40      5678.24      1.00x
BenchmarkReaderRandom_buffered       5691.37      5726.92      1.01x
BenchmarkReaderRandomNoCopy          3795.09      3831.44      1.01x
BenchmarkReaderConstant              30.79        30.50        0.99x
BenchmarkReaderConstant_buffered     30.74        30.48        0.99x
BenchmarkReaderConstantNoCopy        29.34        29.29        1.00x

##Modified PR (inlined struct literal)

Raw go test output:

PASS
BenchmarkReaderManpage            1000000     19398     ns/op  131.45   MB/s
BenchmarkReaderManpage_buffered   1000000     19347     ns/op  131.80   MB/s
BenchmarkReaderManpageNoCopy      1000000     19314     ns/op  132.02   MB/s
BenchmarkReaderJSON               50000       319364    ns/op  76.49    MB/s
BenchmarkReaderJSON_buffered      50000       333882    ns/op  67.62    MB/s
BenchmarkReaderJSONNoCopy         50000       336380    ns/op  67.12    MB/s
BenchmarkReaderRandom             10000       1870011   ns/op  5608.70  MB/s
BenchmarkReaderRandom_buffered    10000       1843386   ns/op  5689.01  MB/s
BenchmarkReaderRandomNoCopy       10000       2748211   ns/op  3815.95  MB/s
BenchmarkReaderConstant           1000        16192587  ns/op  30.61    MB/s
BenchmarkReaderConstant_buffered  1000        16193977  ns/op  30.48    MB/s
BenchmarkReaderConstantNoCopy     1000        16944641  ns/op  29.13    MB/s
ok                                github.com/mreiferson/go-snappystream  244.296s

Difference from "master" created with benchcmp

benchmark                            old ns/op     new ns/op     delta
BenchmarkReaderManpage               20219         19324         -4.43%
BenchmarkReaderManpage_buffered      20150         19341         -4.01%
BenchmarkReaderManpageNoCopy         24238         24155         -0.34%
BenchmarkReaderJSON                  318067        318259        +0.06%
BenchmarkReaderJSON_buffered         329900        328553        -0.41%
BenchmarkReaderJSONNoCopy            383377        375546        -2.04%
BenchmarkReaderRandom                1851622       1858935       +0.39%
BenchmarkReaderRandom_buffered       1842622       1839555       -0.17%
BenchmarkReaderRandomNoCopy          2763322       2745518       -0.64%
BenchmarkReaderConstant              16101400      16116817      +0.10%
BenchmarkReaderConstant_buffered     16059995      16095118      +0.22%
BenchmarkReaderConstantNoCopy        16823845      16858126      +0.20%

benchmark                            old MB/s     new MB/s     speedup
BenchmarkReaderManpage               126.11       131.96       1.05x
BenchmarkReaderManpage_buffered      126.55       131.84       1.04x
BenchmarkReaderManpageNoCopy         105.21       105.57       1.00x
BenchmarkReaderJSON                  76.80        76.75        1.00x
BenchmarkReaderJSON_buffered         68.44        68.72        1.00x
BenchmarkReaderJSONNoCopy            58.89        60.12        1.02x
BenchmarkReaderRandom                5664.40      5642.12      1.00x
BenchmarkReaderRandom_buffered       5691.37      5700.86      1.00x
BenchmarkReaderRandomNoCopy          3795.09      3819.70      1.01x
BenchmarkReaderConstant              30.79        30.76        1.00x
BenchmarkReaderConstant_buffered     30.74        30.67        1.00x
BenchmarkReaderConstantNoCopy        29.34        29.28        1.00x

Finally, the difference between the original PR ("old") and the modified PR ("new") from benchcmp though I think this is more of academic interest. The real important numbers are the difference from master and these numbers can obfuscate that.

benchmark                            old ns/op     new ns/op     delta
BenchmarkReaderManpage               19615         19324         -1.48%
BenchmarkReaderManpage_buffered      19615         19341         -1.40%
BenchmarkReaderManpageNoCopy         24093         24155         +0.26%
BenchmarkReaderJSON                  314540        318259        +1.18%
BenchmarkReaderJSON_buffered         322778        328553        +1.79%
BenchmarkReaderJSONNoCopy            372792        375546        +0.74%
BenchmarkReaderRandom                1847109       1858935       +0.64%
BenchmarkReaderRandom_buffered       1831186       1839555       +0.46%
BenchmarkReaderRandomNoCopy          2737107       2745518       +0.31%
BenchmarkReaderConstant              16250396      16116817      -0.82%
BenchmarkReaderConstant_buffered     16193529      16095118      -0.61%
BenchmarkReaderConstantNoCopy        16849812      16858126      +0.05%

benchmark                            old MB/s     new MB/s     speedup
BenchmarkReaderManpage               130.00       131.96       1.02x
BenchmarkReaderManpage_buffered      130.00       131.84       1.01x
BenchmarkReaderManpageNoCopy         105.84       105.57       1.00x
BenchmarkReaderJSON                  77.66        76.75        0.99x
BenchmarkReaderJSON_buffered         69.95        68.72        0.98x
BenchmarkReaderJSONNoCopy            60.56        60.12        0.99x
BenchmarkReaderRandom                5678.24      5642.12      0.99x
BenchmarkReaderRandom_buffered       5726.92      5700.86      1.00x
BenchmarkReaderRandomNoCopy          3831.44      3819.70      1.00x
BenchmarkReaderConstant              30.50        30.76        1.01x
BenchmarkReaderConstant_buffered     30.48        30.67        1.01x
BenchmarkReaderConstantNoCopy        29.29        29.28        1.00x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment