benchmark_harness 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ree@bh
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ gem "easystats"
9
+
10
+ group :development do
11
+ gem "rspec", "~> 2.3.0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.5.2"
14
+ gem "rcov", ">= 0"
15
+ gem "ruby-debug"
16
+ gem "mocha"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ columnize (0.3.2)
5
+ diff-lcs (1.1.2)
6
+ easystats (0.0.7)
7
+ git (1.2.5)
8
+ jeweler (1.5.2)
9
+ bundler (~> 1.0.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ linecache (0.43)
13
+ mocha (0.9.12)
14
+ rake (0.8.7)
15
+ rcov (0.9.9)
16
+ rspec (2.3.0)
17
+ rspec-core (~> 2.3.0)
18
+ rspec-expectations (~> 2.3.0)
19
+ rspec-mocks (~> 2.3.0)
20
+ rspec-core (2.3.1)
21
+ rspec-expectations (2.3.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.3.0)
24
+ ruby-debug (0.10.4)
25
+ columnize (>= 0.1)
26
+ ruby-debug-base (~> 0.10.4.0)
27
+ ruby-debug-base (0.10.4)
28
+ linecache (>= 0.3)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.0.0)
35
+ easystats
36
+ jeweler (~> 1.5.2)
37
+ mocha
38
+ rcov
39
+ rspec (~> 2.3.0)
40
+ ruby-debug
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Daniel Higginbotham
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = benchmark_harness
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to benchmark_harness
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Daniel Higginbotham. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "benchmark_harness"
16
+ gem.homepage = "http://github.com/flyingmachine/benchmark_harness"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{harness for running benchmark multiple times and running stats on the results}
19
+ gem.description = %Q{harness for running benchmark multiple times and running stats on the results}
20
+ gem.email = "daniel@flyingmachinestudios.com"
21
+ gem.authors = ["Daniel Higginbotham"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "benchmark_harness #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,78 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{benchmark_harness}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Daniel Higginbotham"]
12
+ s.date = %q{2011-03-29}
13
+ s.description = %q{harness for running benchmark multiple times and running stats on the results}
14
+ s.email = %q{daniel@flyingmachinestudios.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".rvmrc",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "benchmark_harness.gemspec",
30
+ "lib/benchmark_harness.rb",
31
+ "lib/benchmark_harness/collection.rb",
32
+ "spec/benchmark_harness_spec.rb",
33
+ "spec/fixtures/string_example.rb",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/flyingmachine/benchmark_harness}
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.7}
40
+ s.summary = %q{harness for running benchmark multiple times and running stats on the results}
41
+ s.test_files = [
42
+ "spec/benchmark_harness_spec.rb",
43
+ "spec/fixtures/string_example.rb",
44
+ "spec/spec_helper.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<easystats>, [">= 0"])
53
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
54
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
56
+ s.add_development_dependency(%q<rcov>, [">= 0"])
57
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
58
+ s.add_development_dependency(%q<mocha>, [">= 0"])
59
+ else
60
+ s.add_dependency(%q<easystats>, [">= 0"])
61
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
64
+ s.add_dependency(%q<rcov>, [">= 0"])
65
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
66
+ s.add_dependency(%q<mocha>, [">= 0"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<easystats>, [">= 0"])
70
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
73
+ s.add_dependency(%q<rcov>, [">= 0"])
74
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
75
+ s.add_dependency(%q<mocha>, [">= 0"])
76
+ end
77
+ end
78
+
@@ -0,0 +1,30 @@
1
+ require 'singleton'
2
+ require 'forwardable'
3
+ require 'benchmark'
4
+ require 'easystats'
5
+
6
+ require 'benchmark_harness/collection'
7
+
8
+ class BenchmarkHarness
9
+ include Singleton
10
+
11
+ class << self
12
+ extend Forwardable
13
+ def_delegators :instance, :collections, :measure, :flush!
14
+ end
15
+
16
+ def collections
17
+ @collections ||= Hash.new{|h,k| h[k] = Collection.new}
18
+ end
19
+
20
+ def flush!
21
+ @collections = nil
22
+ end
23
+
24
+ def measure(collection_name)
25
+ m = Benchmark.measure{
26
+ yield
27
+ }
28
+ collections[collection_name] << m.to_a[1..-1]
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ class BenchmarkHarness
2
+ class Collection < Array
3
+ # order corresponds to values in each sample
4
+ KEYS = [:user, :system, :children_user, :children_system, :real]
5
+ STATS = [:mean, :median, :mode, :range, :standard_deviation, :variance]
6
+ STATS_HUMAN = STATS.collect{|s| s.to_s.sub(/_/, " ").capitalize}
7
+
8
+ def reconciled
9
+ return @reconciled if @reconciled
10
+ @reconciled = Hash.new{|h,k| h[k] = []}
11
+ self.each do |sample|
12
+ KEYS.each_with_index do |key, index|
13
+ @reconciled[key] << sample[index]
14
+ end
15
+ end
16
+ @reconciled
17
+ end
18
+
19
+ # Specify that the corresponding easystats method can be used
20
+ # also defines the method so that it can optionally take a key.
21
+ # If they key is present, return result for just that vector;
22
+ # otherwise return hash of results for all keys/vectors
23
+ [:mean, :median, :mode, :range, :standard_deviation, :variance].each do |method_name|
24
+ class_eval <<-END
25
+ def #{method_name}(key = nil)
26
+ if key
27
+ reconciled[key].#{method_name}
28
+ else
29
+ result = {}
30
+ KEYS.each do |key|
31
+ result[key] = reconciled[key].#{method_name}
32
+ end
33
+ result
34
+ end
35
+ end
36
+ END
37
+ end
38
+
39
+ # Formatted output
40
+ def print
41
+ label_size = STATS_HUMAN.max{|a, b| a.size <=> b.size}.size
42
+ puts sprintf("%#{label_size}s %d", "Samples:", self.size)
43
+ puts "Displaying user, system, children user, children system, real"
44
+ STATS_HUMAN.each_with_index do |label, i|
45
+ puts sprintf("%#{label_size}s: %g %g %g %g %g", label, *KEYS.collect{|k| self.send(STATS[i], k)})
46
+ end
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,96 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "BenchmarkHarness" do
4
+ after :each do
5
+ BenchmarkHarness.flush!
6
+ end
7
+
8
+ # #measure used in StringExample
9
+ describe "#measure" do
10
+ it "should add each instance of a run to a named collection" do
11
+ 2.times{
12
+ StringExample.concatenate_with_plus("Hello ", "Dave")
13
+ StringExample.concatenate_with_append("Hello ", "Dave")
14
+ }
15
+ BenchmarkHarness.collections[:plus].size.should == 2
16
+ BenchmarkHarness.collections[:append].size.should == 2
17
+ end
18
+ end
19
+
20
+ describe "Collection" do
21
+ it "should provide a mean, median, mode, range, standard deviation, and variance for each kind of time if no key provided" do
22
+ Benchmark::Tms.any_instance.stubs(:to_a).returns((1..6).to_a)
23
+ 2.times{
24
+ StringExample.concatenate_with_plus("Hello ", "Dave")
25
+ }
26
+
27
+ BenchmarkHarness.collections[:plus].mean().should == {
28
+ :user => 2,
29
+ :system => 3,
30
+ :children_user => 4,
31
+ :children_system => 5,
32
+ :real => 6
33
+ }
34
+
35
+ BenchmarkHarness.collections[:plus].median().should == {
36
+ :user => 2,
37
+ :system => 3,
38
+ :children_user => 4,
39
+ :children_system => 5,
40
+ :real => 6
41
+ }
42
+
43
+ BenchmarkHarness.collections[:plus].mode().should == {
44
+ :user => 2,
45
+ :system => 3,
46
+ :children_user => 4,
47
+ :children_system => 5,
48
+ :real => 6
49
+ }
50
+
51
+ BenchmarkHarness.collections[:plus].range().should == {
52
+ :user => 0,
53
+ :system => 0,
54
+ :children_user => 0,
55
+ :children_system => 0,
56
+ :real => 0
57
+ }
58
+
59
+ BenchmarkHarness.collections[:plus].standard_deviation().should == {
60
+ :user => 0,
61
+ :system => 0,
62
+ :children_user => 0,
63
+ :children_system => 0,
64
+ :real => 0
65
+ }
66
+
67
+ BenchmarkHarness.collections[:plus].variance().should == {
68
+ :user => 0,
69
+ :system => 0,
70
+ :children_user => 0,
71
+ :children_system => 0,
72
+ :real => 0
73
+ }
74
+ end
75
+
76
+ it "should provide *only* the mean, median, mode, range, etc when key is given" do
77
+ Benchmark::Tms.any_instance.stubs(:to_a).returns((1..6).to_a)
78
+ 2.times{
79
+ StringExample.concatenate_with_plus("Hello ", "Dave")
80
+ }
81
+
82
+ BenchmarkHarness.collections[:plus].mean(:user).should == 2
83
+ end
84
+ end
85
+
86
+ describe "#flush" do
87
+ it "should remove all previous samples" do
88
+ 2.times{
89
+ StringExample.concatenate_with_plus("Hello ", "Dave")
90
+ }
91
+ BenchmarkHarness.flush!
92
+
93
+ BenchmarkHarness.collections.should be_empty
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,16 @@
1
+ # Simple string methods for testing benchmarking
2
+ module StringExample
3
+ class << self
4
+ def concatenate_with_plus(first, second)
5
+ BenchmarkHarness.measure(:plus) {
6
+ first + second
7
+ }
8
+ end
9
+
10
+ def concatenate_with_append(first, second)
11
+ BenchmarkHarness.measure(:append) {
12
+ first << second
13
+ }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'benchmark_harness'
5
+ require 'mocha'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ # Require fixtures
12
+ Dir["#{File.dirname(__FILE__)}/fixtures/**/*.rb"].each {|f| require f}
13
+
14
+ RSpec.configure do |config|
15
+
16
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: benchmark_harness
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Daniel Higginbotham
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-29 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :runtime
24
+ name: easystats
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ type: :development
38
+ name: rspec
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 2
47
+ - 3
48
+ - 0
49
+ version: 2.3.0
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ prerelease: false
53
+ type: :development
54
+ name: bundler
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 23
61
+ segments:
62
+ - 1
63
+ - 0
64
+ - 0
65
+ version: 1.0.0
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ prerelease: false
69
+ type: :development
70
+ name: jeweler
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ hash: 7
77
+ segments:
78
+ - 1
79
+ - 5
80
+ - 2
81
+ version: 1.5.2
82
+ requirement: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ prerelease: false
85
+ type: :development
86
+ name: rcov
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirement: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ prerelease: false
99
+ type: :development
100
+ name: ruby-debug
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirement: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ prerelease: false
113
+ type: :development
114
+ name: mocha
115
+ version_requirements: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirement: *id007
125
+ description: harness for running benchmark multiple times and running stats on the results
126
+ email: daniel@flyingmachinestudios.com
127
+ executables: []
128
+
129
+ extensions: []
130
+
131
+ extra_rdoc_files:
132
+ - LICENSE.txt
133
+ - README.rdoc
134
+ files:
135
+ - .document
136
+ - .rspec
137
+ - .rvmrc
138
+ - Gemfile
139
+ - Gemfile.lock
140
+ - LICENSE.txt
141
+ - README.rdoc
142
+ - Rakefile
143
+ - VERSION
144
+ - benchmark_harness.gemspec
145
+ - lib/benchmark_harness.rb
146
+ - lib/benchmark_harness/collection.rb
147
+ - spec/benchmark_harness_spec.rb
148
+ - spec/fixtures/string_example.rb
149
+ - spec/spec_helper.rb
150
+ has_rdoc: true
151
+ homepage: http://github.com/flyingmachine/benchmark_harness
152
+ licenses:
153
+ - MIT
154
+ post_install_message:
155
+ rdoc_options: []
156
+
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ hash: 3
174
+ segments:
175
+ - 0
176
+ version: "0"
177
+ requirements: []
178
+
179
+ rubyforge_project:
180
+ rubygems_version: 1.3.7
181
+ signing_key:
182
+ specification_version: 3
183
+ summary: harness for running benchmark multiple times and running stats on the results
184
+ test_files:
185
+ - spec/benchmark_harness_spec.rb
186
+ - spec/fixtures/string_example.rb
187
+ - spec/spec_helper.rb