benchmark-plot 0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 114e9d216ecac8f1ff8af12dc422bbdbb37b7bf5
4
- data.tar.gz: 7d3e52515be9d788f46ee623e32981a6239829dc
3
+ metadata.gz: ad54756fcf89b2ae23e8f8993bb4738c37ce339d
4
+ data.tar.gz: ae95a1da2c424dc44c7c96b030bc90414a923966
5
5
  SHA512:
6
- metadata.gz: 7880f2edf6bf4698847951bd230400496efcf472d8377ac745c714569d006d081b47f3e68cbdd58013a9bdc11ec53d56352ee029959f91590def4144b3b8836a
7
- data.tar.gz: e7166e9ce00753a6725ea5a58adff933fe2d711c3dde657687702b2447bf27f9c549e134c0fce03b1d00063623877afbfbd222920c9fe44a9b9e4ae42b835a45
6
+ metadata.gz: 3594f791ad1d9267ba901febd3366a5be3d56274ee7c4f2b604a80f085891626db1df27fbfafcb02996638b056573132eb197d6b3f105fe7317200b899846b80
7
+ data.tar.gz: ef3d1b36344b03d0ce0bf5a85ab9e79f469298aee10f912b34b620c7290a20dc2ecd33f66bcd8be472a9e5ed646f09082d1ed1ca59b568c7bbc83ddc9a5703e6
data/.gitignore CHANGED
@@ -28,7 +28,7 @@ build/
28
28
 
29
29
  # for a library or gem, you might want to ignore these files since the code is
30
30
  # intended to run in multiple environments; otherwise, check them in:
31
- # Gemfile.lock
31
+ Gemfile.lock
32
32
  # .ruby-version
33
33
  # .ruby-gemset
34
34
 
data/HISTORY.md CHANGED
@@ -1,3 +1,10 @@
1
1
  # 0.1
2
2
 
3
- * First gem release. Support for basic args and options.
3
+ * First gem release. Support for basic args and options.
4
+
5
+ # 0.1.1
6
+
7
+ * Remove uncalled for puts statement from plotter.rb.
8
+ * Add more examples.
9
+ * More options and default Y axis label of 'Seconds'.
10
+ * Lots of documentation.
data/README.md CHANGED
@@ -1,6 +1,46 @@
1
1
  # benchmark-plot
2
+
2
3
  A Ruby benchmark extension to allow comparative plotting of benchmarks.
3
4
 
5
+ # Usage
6
+
7
+ This gem is mainly useful for benchmarking code over a number of inputs. This input should be supplied in the form of an object capable of calling `#each`.
8
+
9
+ Sample benchmarking script:
10
+
11
+ ``` ruby
12
+ require 'benchmark/plot'
13
+
14
+ class TestArray
15
+ attr_reader :arr
16
+
17
+ def initialize arr
18
+ @arr = arr
19
+ end
20
+
21
+ def to_s
22
+ @arr.size.to_s
23
+ end
24
+ end
25
+
26
+ test_data = [5, 25, 50, 75, 100, 125, 150, 175, 200,250,300]
27
+ test_data.map! {|e| TestArray.new(Array.new(e) {|i| i}) }
28
+
29
+ Benchmark.plot(test_data) do |x|
30
+ x.report("map.flatten") do |data|
31
+ data.arr.map { [nil] }.flatten
32
+ end
33
+
34
+ x.report("flat_map") do |data|
35
+ data.arr.flat_map { [nil] }
36
+ end
37
+ end
38
+ ```
39
+
40
+ Output:
41
+
42
+ ![Benchmarks](examples/mapflat_vs_flat_map/benchmark_plot_graph.png)
43
+
4
44
  # Acknowledgements
5
45
 
6
- @tgxworld for providing the co-working space during the Open Source Breakfast Hack during Red Dot Ruby Conf 2016 where this gem was built.
46
+ [@tgxworld](https://github.com/tgxworld) for providing the co-working space during the Open Source Breakfast Hack during Red Dot Ruby Conference 2016 where this gem was built.
@@ -0,0 +1,2 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
@@ -6,9 +6,8 @@ require 'benchmark/plot/version.rb'
6
6
  Benchmark::Plot::DESCRIPTION = <<MSG
7
7
  benchmark-plot is an extension to the Ruby standard benchmarking library.
8
8
 
9
- It let's you easily create plots in the form of PNG images of any code that you
10
- want to benchmark over a varied number of inputs. It also supports comparative
11
- benchmarking.
9
+ It let's you easily create plots of any code that you want to benchmark over
10
+ a varied number of inputs. It also supports comparative benchmarking.
12
11
  MSG
13
12
 
14
13
  Gem::Specification.new do |spec|
@@ -1,12 +1,26 @@
1
+ require 'benchmark/plot'
2
+
3
+ class TestArray
4
+ attr_reader :arr
5
+
6
+ def initialize arr
7
+ @arr = arr
8
+ end
9
+
10
+ def to_s
11
+ @arr.size.to_s
12
+ end
13
+ end
14
+
1
15
  test_data = [5, 25, 50, 75, 100, 125, 150, 175, 200,250,300]
2
- test_data.map! {|e| Array.new(e) {|i| i} }
16
+ test_data.map! {|e| TestArray.new(Array.new(e) {|i| i}) }
3
17
 
4
18
  Benchmark.plot(test_data) do |x|
5
19
  x.report("map.flatten") do |data|
6
- data.map { [nil] }.flatten
20
+ data.arr.map { [nil] }.flatten
7
21
  end
8
22
 
9
23
  x.report("flat_map") do |data|
10
- data.flat_map { [nil] }
24
+ data.arr.flat_map { [nil] }
11
25
  end
12
- end
26
+ end
@@ -0,0 +1,19 @@
1
+ require 'benchmark/plot'
2
+ require 'matrix'
3
+ require 'nmatrix'
4
+ require 'nmatrix/atlas'
5
+
6
+ sizes = [5, 10, 50, 100, 150, 200]
7
+
8
+ Benchmark.plot sizes, title: "Matrix multiplication",
9
+ file_name: "matrix_multiplication" do |x|
10
+ x.report "NMatrix with ATLAS" do |size|
11
+ n = NMatrix.new([size,size], [1]*size*size, dtype: :float32)
12
+ n.dot(n)
13
+ end
14
+
15
+ x.report "Matrix" do |size|
16
+ n = Matrix[*[[1]*size]*size]
17
+ n * n
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ require 'numo-narray'
2
+ require 'nmatrix'
3
+
@@ -6,6 +6,53 @@ require 'benchmark/plot/report_maker'
6
6
  require 'benchmark/plot/version'
7
7
 
8
8
  module Benchmark
9
+ # Create a plot of the benchmarked code over a varied number of inputs.
10
+ #
11
+ # @param test_data [Enumerable] An object containing the data that is to be
12
+ # used for the benchmarking. This object must be Enumerable, i.e. it must
13
+ # have the `#each` method defined. Each of the constituent objects of
14
+ # `test_data` should have a `#to_s` method defined, which will be used for
15
+ # populating the X axis labels.
16
+ # @param [Hash] opts The options for configuring the graph.
17
+ # @option opts [Symbol, String] :title (:Benchmarks) Title of the graph.
18
+ # @option opts [Symbol, String] :file_name (:benchmark_plot_graph) Name of
19
+ # file to which plot is written.
20
+ # @option opts [Symbol] :time (:real) The kind of time that should be displayed
21
+ # on the graph. Can be `:real` for elapsed real time, `:stime` for System
22
+ # CPU time, `:utime` for User CPU time, `:cstime` for System CPU time of children,
23
+ # `:cutime` for User CPU time of children, and `:total` for the total time
24
+ # that is `:utime + :stime + :cutime + :cstime`.
25
+ # @option opts [TrueClass, FalseClass] :x_labels (true) Whether you want X-axis
26
+ # labels or not.
27
+ # @option opts [String, Symbol] :x_axis_label (nil) X-axis label string.
28
+ # @example Benchmark map{}.flatten vs. flat_map
29
+ # require 'benchmark/plot'
30
+ # class TestArray
31
+ # attr_reader :arr
32
+ #
33
+ # def initialize arr
34
+ # @arr = arr
35
+ # end
36
+ #
37
+ # # The to_s method is called for populating the X axis labels.
38
+ # def to_s
39
+ # @arr.size.to_s
40
+ # end
41
+ # end
42
+ #
43
+ # test_data = [5, 25, 50, 75, 100, 125, 150, 175, 200,250,300]
44
+ # test_data.map! {|e| TestArray.new(Array.new(e) {|i| i}) }
45
+ #
46
+ # Benchmark.plot(test_data) do |x|
47
+ # x.report("map.flatten") do |data|
48
+ # # Here `data` will be of an object of type `TestArray`.
49
+ # data.arr.map { [nil] }.flatten
50
+ # end
51
+ #
52
+ # x.report("flat_map") do |data|
53
+ # data.arr.flat_map { [nil] }
54
+ # end
55
+ # end
9
56
  def self.plot test_data, opts={}, &block
10
57
  include Benchmark::Plot
11
58
 
@@ -7,6 +7,7 @@ module Benchmark
7
7
  @title = opts[:title] || :Benchmarks
8
8
  @time = opts[:time] || :real
9
9
  @x_labels = opts[:x_labels] || true
10
+ @x_axis_label = opts[:x_axis_label]
10
11
  @test_data = test_data
11
12
  end
12
13
 
@@ -22,8 +23,9 @@ module Benchmark
22
23
  plot.data label, time_data
23
24
  end
24
25
  positions = Array.new(@test_data.size) { |i| i }
25
- puts positions.zip(@test_data.map(&:to_s)).to_h
26
26
  plot.labels = positions.zip(@test_data.map(&:to_s)).to_h if @x_labels
27
+ plot.x_axis_label = @x_axis_label if @x_axis_label
28
+ plot.y_axis_label = 'Seconds'
27
29
  plot.write("#{@file_name}.png")
28
30
  end
29
31
 
@@ -1,5 +1,5 @@
1
1
  module Benchmark
2
2
  module Plot
3
- VERSION = "0.1"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benchmark-plot
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sameer Deshmukh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-26 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gruff
@@ -24,12 +24,9 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: |
28
- benchmark-plot is an extension to the Ruby standard benchmarking library.
29
-
30
- It let's you easily create plots in the form of PNG images of any code that you
31
- want to benchmark over a varied number of inputs. It also supports comparative
32
- benchmarking.
27
+ description: "benchmark-plot is an extension to the Ruby standard benchmarking library.\n\nIt
28
+ let's you easily create plots of any code that you want to benchmark over \na varied
29
+ number of inputs. It also supports comparative benchmarking.\n"
33
30
  email:
34
31
  - sameer.deshmukh93@gmail.com
35
32
  executables: []
@@ -40,11 +37,13 @@ files:
40
37
  - HISTORY.md
41
38
  - LICENSE
42
39
  - README.md
40
+ - Rakefile
43
41
  - benchmark-plot.gemspec
44
- - examples/flat_vs_flat_map.rb
45
42
  - examples/mapflat_vs_flat_map/benchmark_plot_graph.png
46
43
  - examples/mapflat_vs_flat_map/flat_vs_flat_map.rb
47
- - examples/matrix_benchmarks.rb
44
+ - examples/matrix_vs_nmatrix/matrix_multiplication/matrix_multiplication.png
45
+ - examples/matrix_vs_nmatrix/matrix_multiplication/matrix_multiplication.rb
46
+ - examples/nmatrix_vs_narray/matrix_creation.rb
48
47
  - lib/benchmark/plot.rb
49
48
  - lib/benchmark/plot/plotter.rb
50
49
  - lib/benchmark/plot/report_maker.rb
@@ -1,26 +0,0 @@
1
- require 'benchmark/plot'
2
-
3
- class TestArray
4
- attr_reader :arr
5
-
6
- def initialize arr
7
- @arr = arr
8
- end
9
-
10
- def to_s
11
- @arr.size.to_s
12
- end
13
- end
14
-
15
- test_data = [5, 25, 50, 75, 100, 125, 150, 175, 200,250,300]
16
- test_data.map! {|e| TestArray.new(Array.new(e) {|i| i}) }
17
-
18
- Benchmark.plot(test_data) do |x|
19
- x.report("map.flatten") do |data|
20
- data.arr.map { [nil] }.flatten
21
- end
22
-
23
- x.report("flat_map") do |data|
24
- data.arr.flat_map { [nil] }
25
- end
26
- end
@@ -1,14 +0,0 @@
1
- require 'nmatrix'
2
- require 'matrix'
3
-
4
- test_data = [5,10,15,20,25,30,35]
5
-
6
- Benchmark.plot(test_data) do |x, data|
7
- x.report("nmatrix creation") do
8
- Array.new(data) { |i| i }
9
- end
10
-
11
- x.report("matrix creation") do
12
- Array.new(data) { |i| i }
13
- end
14
- end