benchmark-plot 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 114e9d216ecac8f1ff8af12dc422bbdbb37b7bf5
4
+ data.tar.gz: 7d3e52515be9d788f46ee623e32981a6239829dc
5
+ SHA512:
6
+ metadata.gz: 7880f2edf6bf4698847951bd230400496efcf472d8377ac745c714569d006d081b47f3e68cbdd58013a9bdc11ec53d56352ee029959f91590def4144b3b8836a
7
+ data.tar.gz: e7166e9ce00753a6725ea5a58adff933fe2d711c3dde657687702b2447bf27f9c549e134c0fce03b1d00063623877afbfbd222920c9fe44a9b9e4ae42b835a45
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/HISTORY.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.1
2
+
3
+ * First gem release. Support for basic args and options.
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2016, Sameer Deshmukh
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of benchmark-plot nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # benchmark-plot
2
+ A Ruby benchmark extension to allow comparative plotting of benchmarks.
3
+
4
+ # Acknowledgements
5
+
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.
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ $:.unshift File.expand_path("../lib", __FILE__)
3
+
4
+ require 'benchmark/plot/version.rb'
5
+
6
+ Benchmark::Plot::DESCRIPTION = <<MSG
7
+ benchmark-plot is an extension to the Ruby standard benchmarking library.
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.
12
+ MSG
13
+
14
+ Gem::Specification.new do |spec|
15
+ spec.name = 'benchmark-plot'
16
+ spec.version = Benchmark::Plot::VERSION
17
+ spec.authors = ['Sameer Deshmukh']
18
+ spec.email = ['sameer.deshmukh93@gmail.com']
19
+ spec.summary = %q{benchmark-plot}
20
+ spec.description = Benchmark::Plot::DESCRIPTION
21
+ spec.homepage = "http://github.com/v0dro/benchmark-plot"
22
+ spec.license = 'BSD-2'
23
+
24
+ spec.files = `git ls-files -z`.split("\x0")
25
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency 'gruff'
30
+ end
@@ -0,0 +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
+
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
@@ -0,0 +1,12 @@
1
+ test_data = [5, 25, 50, 75, 100, 125, 150, 175, 200,250,300]
2
+ test_data.map! {|e| Array.new(e) {|i| i} }
3
+
4
+ Benchmark.plot(test_data) do |x|
5
+ x.report("map.flatten") do |data|
6
+ data.map { [nil] }.flatten
7
+ end
8
+
9
+ x.report("flat_map") do |data|
10
+ data.flat_map { [nil] }
11
+ end
12
+ end
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,17 @@
1
+ require 'benchmark'
2
+ require 'gruff'
3
+
4
+ require 'benchmark/plot/plotter'
5
+ require 'benchmark/plot/report_maker'
6
+ require 'benchmark/plot/version'
7
+
8
+ module Benchmark
9
+ def self.plot test_data, opts={}, &block
10
+ include Benchmark::Plot
11
+
12
+ reporter = ReportMaker.new(test_data)
13
+ yield(reporter)
14
+ plotter = Plotter.new reporter, test_data, opts
15
+ plotter.plot
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ module Benchmark
2
+ module Plot
3
+ class Plotter
4
+ def initialize reporter, test_data, opts
5
+ @reporter = reporter
6
+ @file_name = opts[:file_name] || :benchmark_plot_graph
7
+ @title = opts[:title] || :Benchmarks
8
+ @time = opts[:time] || :real
9
+ @x_labels = opts[:x_labels] || true
10
+ @test_data = test_data
11
+ end
12
+
13
+ def plot
14
+ plot = Gruff::Line.new
15
+ plot.title = @title.to_s
16
+ reports = @reporter.reports
17
+
18
+ reports.each do |label, report|
19
+ time_data = report.map do |tms|
20
+ tms.send(@time)
21
+ end
22
+ plot.data label, time_data
23
+ end
24
+ positions = Array.new(@test_data.size) { |i| i }
25
+ puts positions.zip(@test_data.map(&:to_s)).to_h
26
+ plot.labels = positions.zip(@test_data.map(&:to_s)).to_h if @x_labels
27
+ plot.write("#{@file_name}.png")
28
+ end
29
+
30
+ def all_labels
31
+ @reporter.reports.keys
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ module Benchmark
2
+ module Plot
3
+ class ReportMaker
4
+ def initialize data
5
+ @data = data
6
+ @reports = {}
7
+ end
8
+
9
+ def report(label,&block)
10
+ results_array = @data.each_with_object([]) do |d, results|
11
+ lmb = lambda { block.call(d) }
12
+ results << Benchmark.measure(label, &lmb)
13
+ end
14
+ @reports[label] = results_array
15
+ end
16
+
17
+ # An array of Benchmark::Tms objects representing each item.
18
+ attr_reader :reports
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Benchmark
2
+ module Plot
3
+ VERSION = "0.1"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Benchmark do
4
+ context ".plot" do
5
+ # TODO: write tests
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ require 'benchmark/plot'
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: benchmark-plot
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Sameer Deshmukh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gruff
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
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.
33
+ email:
34
+ - sameer.deshmukh93@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - ".gitignore"
40
+ - HISTORY.md
41
+ - LICENSE
42
+ - README.md
43
+ - benchmark-plot.gemspec
44
+ - examples/flat_vs_flat_map.rb
45
+ - examples/mapflat_vs_flat_map/benchmark_plot_graph.png
46
+ - examples/mapflat_vs_flat_map/flat_vs_flat_map.rb
47
+ - examples/matrix_benchmarks.rb
48
+ - lib/benchmark/plot.rb
49
+ - lib/benchmark/plot/plotter.rb
50
+ - lib/benchmark/plot/report_maker.rb
51
+ - lib/benchmark/plot/version.rb
52
+ - spec/benchmark_plot_spec.rb
53
+ - spec/spec_helper.rb
54
+ homepage: http://github.com/v0dro/benchmark-plot
55
+ licenses:
56
+ - BSD-2
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.4.6
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: benchmark-plot
78
+ test_files:
79
+ - spec/benchmark_plot_spec.rb
80
+ - spec/spec_helper.rb
81
+ has_rdoc: