Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction benchmark-plot at PRUG

Introduction benchmark-plot at PRUG

Here I present an introduction to benchmark-plot, a gem that I've developed for easily creating plots of benchmarks. Presented at Pune Ruby Users Group at the July Meetup.

Sameer Deshmukh

July 02, 2016
Tweet

More Decks by Sameer Deshmukh

Other Decks in Programming

Transcript

  1. Compare the same code before and after refactor. Compare performance

    of two distinct ways of doing the same thing. Curiosity.
  2. Array#map -> Array#flatten a.map { |e| [e,e] }.flatten # =>

    [1,1,2,3,3.... Array#flat_map a.flat_map { |e| [e,e] } # => [1,1,2,2,3,3.... a = (1..size).to_a
  3. require 'benchmark' Benchmark.bm do |x| x.report("map.flat") do (1..1000).to_a.map { |e|

    [e,e] }.flatten end x.report("flat_map") do (1..1000).to_a.flat_map { |e| [e,e] } end end
  4. user system total real map.flat 0.000 0.000 0.000 ( 0.001025)

    flat_map 0.000 0.000 0.000 ( 0.000569)
  5. require 'benchmark' Benchmark.bm do |x| [100, 500, 1000, 5000].each do

    |size| x.report("map.flat") do (1..size).to_a.map { |e| [e,e] }.flatten end x.report("flat_map") do (1..size).to_a.flat_map { |e| [e,e] } end end end
  6. user system total real map.flat 0.000 0.000 0.000 ( 0.000069)

    flat_map 0.000 0.000 0.000 ( 0.000062) map.flat 0.000 0.000 0.000 ( 0.000314) flat_map 0.000 0.000 0.000 ( 0.000259) map.flat 0.000 0.000 0.000 ( 0.000750) flat_map 0.000 0.000 0.000 ( 0.000409) map.flat 0.000 0.000 0.000 ( 0.003270) flat_map 0.010 0.000 0.010 ( 0.001771)
  7. require 'benchmark/plot' arr = [100, 500, 1000, 5000] Benchmark.plot(arr) do

    |x| x.report("map.flat") do |size| (1..size).to_a.map { |e| [e,e] }.flatten end x.report("flat_map") do |size| (1..size).to_a.flat_map { |e| [e,e] } end end
  8. require 'benchmark/plot' arr = [100, 500, 1000, 5000] arr.map! {

    |size| (1..size).to_a } Benchmark.plot(arr) do |x| x.report("map.flat") do |a| a.map { |e| [e,e] }.flatten end x.report("flat_map") do |a| a.flat_map { |e| [e,e] } end end
  9. require 'benchmark/plot' arr = [100, 500, 1000, 5000] arr.map! {

    |size| (1..size).to_a } Benchmark.plot(arr) do |x| x.report("map.flat") do |a| a.map { |e| [e,e] }.flatten end x.report("flat_map") do |a| a.flat_map { |e| [e,e] } end end
  10. require 'benchmark/plot' arr = [100, 500, 1000, 5000] arr.map! {

    |size| TestArray.new (1..size).to_a } Benchmark.plot(arr) do |x| x.report("map.flat") do |a| a.data.map { |e| [e,e] }.flatten end x.report("flat_map") do |a| a.data.flat_map { |e| [e,e] } end end
  11. Customization Options • :title – Change the title of the

    graph. • :x_labels – Toggle whether X axis labels should be displayed. • :x_axis_label – A string for the label of the X axis. • :time – The kind of time that you want plotted (real time or system CPU time or user CPU time). • :file_name – The file name of the graph.