bnchmrkr 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/bnchmrkr.rb +22 -8
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 214df34c63b9b084f735e0f68b852f7b133cac08
4
- data.tar.gz: 0a62535f2639dfcab95c35c4a90740b8ba5b8207
3
+ metadata.gz: 81543d9e532bbc61a99896b8019287a145dcd15b
4
+ data.tar.gz: 9272a8d8e1764d176f4e5b8d8e049a6e78f6c181
5
5
  SHA512:
6
- metadata.gz: be45d3fd8037efeeea35eda76b1ebb2258d5b96a09e95fe5e525cf77f5907e243f7a7f3e2c5c6a20fb9b5a2ad5eff1546013a857f74a26fb7b6f35c723c2fabf
7
- data.tar.gz: dedbf34a52fccd4e5a45387fc8bfc412cff22b0421d9380a5d59560644d445fbea82a5f4aaf5d26b2047228eba72fedb47ba2cb4cd92ce057f616e6e75a440aa
6
+ metadata.gz: a8ac397da4feaa130d033aa0d014faef00cc256bbbb5646f8f3b503a9fad1ac71b0f1c5e58f22c180e9009c25aadeda5e8e80c142a74455eeec0ab243b13a176
7
+ data.tar.gz: 717623a9113bb53a82ad04fdfd10271034cf13643eaae0b713405c3e47cfb8519dc471baeed90f9befa39939994c1dc224ae55c48cc6cbb5c266aaf820eddb53
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/bnchmrkr.rb CHANGED
@@ -179,25 +179,39 @@ class Bnchmrkr
179
179
  self.results[name] << measure
180
180
  end
181
181
 
182
+ # +mode_precision+ Fixnum indicating number of digits to consider during mode calculation, default to 0, which will use all signal
182
183
  # from existing results, generate some statistics per lambda type
183
- def calculate_per_lambda
184
+ def calculate_per_lambda(mode_precision = 0)
184
185
  hash = Hash.new
185
186
 
186
- # TODO come up with way to not recompute unless contents have changed
187
+ # TODO come up with way to not recompute unless contents have changed -- https://github.com/chorankates/bnchmrkr/issues/3
187
188
 
188
189
  @results.each_pair do |name, measures|
189
- sorted = measures.sort { |a,b| a.real <=> b.real }
190
+ hash[name] = Hash.new
191
+ frequency_hash = Hash.new(0)
192
+ mode_candidate = { :frequency => 1, :operand => nil }
193
+ total = 0
190
194
 
191
- hash[name] = Hash.new
195
+ sorted = measures.sort { |a,b| a.real <=> b.real }
196
+ measures.each do |measure|
197
+ operand = mode_precision.equal?(0) ? measure.real : measure.real.round(mode_precision)
198
+ frequency_hash[operand] += 1
199
+
200
+ # i hate maths
201
+ if frequency_hash[operand] > mode_candidate[:frequency] and frequency_hash[operand] > 1
202
+ mode_candidate[:frequency] = frequency_hash[operand]
203
+ mode_candidate[:operand] = operand
204
+ end
205
+ end
192
206
 
193
- total = 0
194
- # TODO add the mode
195
207
  measures.collect {|m| total += m.real }
196
208
  hash[name][:fastest] = sorted.first.real
197
209
  hash[name][:slowest] = sorted.last.real
198
- hash[name][:mean] = sprintf('%5f', total / sorted.size)
210
+ hash[name][:mean] = sprintf('%5f', total / sorted.size).to_f
199
211
  hash[name][:median] = sorted[(sorted.size / 2)].real
200
- hash[name][:total] = sprintf('%5f', total)
212
+ # TODO need to handle the rare case that we have multiple modes -- https://github.com/chorankates/bnchmrkr/issues/4
213
+ hash[name][:mode] = mode_candidate[:operand] # collect key name with highest value
214
+ hash[name][:total] = sprintf('%5f', total).to_f
201
215
  end
202
216
 
203
217
  hash
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bnchmrkr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conor Horan-Kates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-02 00:00:00.000000000 Z
11
+ date: 2016-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake