benchmark_harness 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -2
- data/VERSION +1 -1
- data/benchmark_harness.gemspec +2 -4
- data/lib/benchmark_harness/collection.rb +1 -1
- data/lib/benchmark_harness/stats.rb +176 -0
- data/lib/benchmark_harness.rb +5 -1
- metadata +16 -29
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/benchmark_harness.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{benchmark_harness}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Higginbotham"]
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"benchmark_harness.gemspec",
|
30
30
|
"lib/benchmark_harness.rb",
|
31
31
|
"lib/benchmark_harness/collection.rb",
|
32
|
+
"lib/benchmark_harness/stats.rb",
|
32
33
|
"spec/benchmark_harness_spec.rb",
|
33
34
|
"spec/fixtures/nested_example.rb",
|
34
35
|
"spec/fixtures/string_example.rb",
|
@@ -51,7 +52,6 @@ Gem::Specification.new do |s|
|
|
51
52
|
s.specification_version = 3
|
52
53
|
|
53
54
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
|
-
s.add_runtime_dependency(%q<easystats>, [">= 0"])
|
55
55
|
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
56
56
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
57
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
@@ -59,7 +59,6 @@ Gem::Specification.new do |s|
|
|
59
59
|
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
60
60
|
s.add_development_dependency(%q<mocha>, [">= 0"])
|
61
61
|
else
|
62
|
-
s.add_dependency(%q<easystats>, [">= 0"])
|
63
62
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
64
63
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
64
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
@@ -68,7 +67,6 @@ Gem::Specification.new do |s|
|
|
68
67
|
s.add_dependency(%q<mocha>, [">= 0"])
|
69
68
|
end
|
70
69
|
else
|
71
|
-
s.add_dependency(%q<easystats>, [">= 0"])
|
72
70
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
73
71
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
74
72
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class BenchmarkHarness
|
2
2
|
class Collection < Array
|
3
|
+
|
3
4
|
# order corresponds to values in each sample
|
4
5
|
KEYS = [:user, :system, :children_user, :children_system, :real]
|
5
6
|
STATS = [:mean, :median, :mode, :range, :standard_deviation, :variance]
|
@@ -45,6 +46,5 @@ class BenchmarkHarness
|
|
45
46
|
puts sprintf("%#{label_size}s: %g %g %g %g %g", label, *KEYS.collect{|k| self.send(STATS[i], k)})
|
46
47
|
end
|
47
48
|
end
|
48
|
-
|
49
49
|
end
|
50
50
|
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
class BenchmarkHarness
|
2
|
+
# copied from https://github.com/mgrigajtis/easystats/blob/master/lib/easystats.rb until orig author fixes
|
3
|
+
# sum conflict problem
|
4
|
+
module Stats
|
5
|
+
# take in an array of numbers and calculate the sum
|
6
|
+
def self.included(base)
|
7
|
+
unless base.method_defined? :sum
|
8
|
+
base.class_eval do
|
9
|
+
define_method :sum do
|
10
|
+
data = self
|
11
|
+
sum_of_numbers = 0
|
12
|
+
|
13
|
+
# Get the total sum only if there are actually numbers to total
|
14
|
+
if data.count > 0
|
15
|
+
data.each do |num|
|
16
|
+
sum_of_numbers += num
|
17
|
+
end
|
18
|
+
else
|
19
|
+
sum_of_numbers = 0
|
20
|
+
end
|
21
|
+
|
22
|
+
sum_of_numbers
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# take in an array of numbers and calculate the mean (average)
|
29
|
+
def mean
|
30
|
+
data = self
|
31
|
+
|
32
|
+
# Check to make sure there are numbers to avoid division by 0
|
33
|
+
if data.count > 0
|
34
|
+
self.sum / data.count.to_f
|
35
|
+
else
|
36
|
+
0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
alias_method :average, :mean
|
40
|
+
|
41
|
+
# this is an internat function (technically the developer can use it but should have no need)
|
42
|
+
# this function returns the sum of each squared difference of mean
|
43
|
+
def sum_of_deviations_squared
|
44
|
+
data = self
|
45
|
+
|
46
|
+
deviations = Array.new
|
47
|
+
average = self.mean
|
48
|
+
sum_of_deviations_squared = 0
|
49
|
+
|
50
|
+
data.each do |num|
|
51
|
+
deviations.push((num-average)**2)
|
52
|
+
end
|
53
|
+
|
54
|
+
deviations.each do |num|
|
55
|
+
sum_of_deviations_squared += num
|
56
|
+
end
|
57
|
+
|
58
|
+
sum_of_deviations_squared
|
59
|
+
end
|
60
|
+
|
61
|
+
# take in an array of numbers and calculate the standard deviation
|
62
|
+
def standard_deviation
|
63
|
+
data = self
|
64
|
+
sum_of_deviations_squared = self.sum_of_deviations_squared
|
65
|
+
|
66
|
+
if data.count > 1
|
67
|
+
Math::sqrt(sum_of_deviations_squared / (data.count-1))
|
68
|
+
else
|
69
|
+
0
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def variance
|
74
|
+
data = self
|
75
|
+
average = self.mean
|
76
|
+
sum_of_deviations = self.sum_of_deviations_squared
|
77
|
+
|
78
|
+
if data.count > 0
|
79
|
+
sum_of_deviations / data.count.to_f
|
80
|
+
else
|
81
|
+
0
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# take in the array of numbers and calculate the median
|
86
|
+
def median
|
87
|
+
data = self
|
88
|
+
|
89
|
+
halfway = data.count / 2
|
90
|
+
|
91
|
+
# Sort the array
|
92
|
+
data = data.sort
|
93
|
+
|
94
|
+
# The median will be different based on the number of numbers in the array
|
95
|
+
# If there is an even number in the array
|
96
|
+
if(data.count % 2) == 0
|
97
|
+
median = (data[halfway] + data[halfway-1]) / 2.0
|
98
|
+
|
99
|
+
# Else, there is an odd number of elements in the array
|
100
|
+
else
|
101
|
+
median = data[halfway]
|
102
|
+
end
|
103
|
+
|
104
|
+
median
|
105
|
+
end
|
106
|
+
|
107
|
+
# take in an array of numbers and calculate the range
|
108
|
+
def range
|
109
|
+
data = self
|
110
|
+
data = data.sort
|
111
|
+
data[data.count-1] - data[0]
|
112
|
+
end
|
113
|
+
|
114
|
+
# take in an array of numbers and return the mode
|
115
|
+
def mode
|
116
|
+
data = self
|
117
|
+
|
118
|
+
# Sort the array
|
119
|
+
data = data.sort
|
120
|
+
|
121
|
+
# create a flag to tell the user if all the numbers only appear once
|
122
|
+
no_mode = true
|
123
|
+
|
124
|
+
# The variable that will hold the highest number
|
125
|
+
highest_value = 0
|
126
|
+
|
127
|
+
# The variable that holds the most time the value appears
|
128
|
+
most_times = 0
|
129
|
+
|
130
|
+
# Create a new hash to hold the numbers
|
131
|
+
tmp = Hash.new
|
132
|
+
|
133
|
+
# Populate the hash
|
134
|
+
data.each do |num|
|
135
|
+
if tmp["#{num}"].nil? == false
|
136
|
+
tmp["#{num}"] = tmp["#{num}"].to_i + 1
|
137
|
+
else
|
138
|
+
tmp["#{num}"] = 1
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Check to make sure that there is a mode
|
143
|
+
data.each do |num|
|
144
|
+
if tmp["#{num}"].to_i > 1
|
145
|
+
no_mode = false
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
if no_mode == true
|
150
|
+
0
|
151
|
+
else
|
152
|
+
data.each do |num|
|
153
|
+
if tmp["#{num}"].to_i > most_times
|
154
|
+
highest_value = num
|
155
|
+
most_times = tmp["#{num}"]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# now loop through again just to make sure another number doesn't appear an equal number of times
|
160
|
+
data.each do |num|
|
161
|
+
if num != highest_value
|
162
|
+
if tmp["#{num}"].to_i == most_times
|
163
|
+
no_mode = true
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
if no_mode == true
|
169
|
+
0
|
170
|
+
else
|
171
|
+
highest_value
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
data/lib/benchmark_harness.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require 'forwardable'
|
3
3
|
require 'benchmark'
|
4
|
-
require 'easystats'
|
5
4
|
|
5
|
+
require 'benchmark_harness/stats'
|
6
6
|
require 'benchmark_harness/collection'
|
7
7
|
|
8
8
|
class BenchmarkHarness
|
@@ -74,4 +74,8 @@ class BenchmarkHarness
|
|
74
74
|
end
|
75
75
|
parent_constant
|
76
76
|
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class Array
|
80
|
+
include BenchmarkHarness::Stats
|
77
81
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: benchmark_harness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Higginbotham
|
@@ -18,25 +18,11 @@ cert_chain: []
|
|
18
18
|
date: 2011-03-29 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
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
21
|
- !ruby/object:Gem::Dependency
|
36
22
|
prerelease: false
|
37
23
|
type: :development
|
38
24
|
name: rspec
|
39
|
-
version_requirements: &
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
40
26
|
none: false
|
41
27
|
requirements:
|
42
28
|
- - ~>
|
@@ -47,12 +33,12 @@ dependencies:
|
|
47
33
|
- 3
|
48
34
|
- 0
|
49
35
|
version: 2.3.0
|
50
|
-
requirement: *
|
36
|
+
requirement: *id001
|
51
37
|
- !ruby/object:Gem::Dependency
|
52
38
|
prerelease: false
|
53
39
|
type: :development
|
54
40
|
name: bundler
|
55
|
-
version_requirements: &
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
56
42
|
none: false
|
57
43
|
requirements:
|
58
44
|
- - ~>
|
@@ -63,12 +49,12 @@ dependencies:
|
|
63
49
|
- 0
|
64
50
|
- 0
|
65
51
|
version: 1.0.0
|
66
|
-
requirement: *
|
52
|
+
requirement: *id002
|
67
53
|
- !ruby/object:Gem::Dependency
|
68
54
|
prerelease: false
|
69
55
|
type: :development
|
70
56
|
name: jeweler
|
71
|
-
version_requirements: &
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
72
58
|
none: false
|
73
59
|
requirements:
|
74
60
|
- - ~>
|
@@ -79,12 +65,12 @@ dependencies:
|
|
79
65
|
- 5
|
80
66
|
- 2
|
81
67
|
version: 1.5.2
|
82
|
-
requirement: *
|
68
|
+
requirement: *id003
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
prerelease: false
|
85
71
|
type: :development
|
86
72
|
name: rcov
|
87
|
-
version_requirements: &
|
73
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
88
74
|
none: false
|
89
75
|
requirements:
|
90
76
|
- - ">="
|
@@ -93,12 +79,12 @@ dependencies:
|
|
93
79
|
segments:
|
94
80
|
- 0
|
95
81
|
version: "0"
|
96
|
-
requirement: *
|
82
|
+
requirement: *id004
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
prerelease: false
|
99
85
|
type: :development
|
100
86
|
name: ruby-debug
|
101
|
-
version_requirements: &
|
87
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
102
88
|
none: false
|
103
89
|
requirements:
|
104
90
|
- - ">="
|
@@ -107,12 +93,12 @@ dependencies:
|
|
107
93
|
segments:
|
108
94
|
- 0
|
109
95
|
version: "0"
|
110
|
-
requirement: *
|
96
|
+
requirement: *id005
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
prerelease: false
|
113
99
|
type: :development
|
114
100
|
name: mocha
|
115
|
-
version_requirements: &
|
101
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
116
102
|
none: false
|
117
103
|
requirements:
|
118
104
|
- - ">="
|
@@ -121,7 +107,7 @@ dependencies:
|
|
121
107
|
segments:
|
122
108
|
- 0
|
123
109
|
version: "0"
|
124
|
-
requirement: *
|
110
|
+
requirement: *id006
|
125
111
|
description: harness for running benchmark multiple times and running stats on the results
|
126
112
|
email: daniel@flyingmachinestudios.com
|
127
113
|
executables: []
|
@@ -144,6 +130,7 @@ files:
|
|
144
130
|
- benchmark_harness.gemspec
|
145
131
|
- lib/benchmark_harness.rb
|
146
132
|
- lib/benchmark_harness/collection.rb
|
133
|
+
- lib/benchmark_harness/stats.rb
|
147
134
|
- spec/benchmark_harness_spec.rb
|
148
135
|
- spec/fixtures/nested_example.rb
|
149
136
|
- spec/fixtures/string_example.rb
|