-
Notifications
You must be signed in to change notification settings - Fork 5
/
report.rb
46 lines (37 loc) · 1.18 KB
/
report.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Benchmark
module BigO
class Report
attr_accessor :per_iterations
attr_reader :entries
def initialize
@per_iterations = 0
@entries = {}
end
def add_entry label, microseconds, iters, ips, measurement_cycle
group_label = label.split(' ').first
@entries[group_label] ||= []
@entries[group_label] << Benchmark::IPS::Report::Entry.new(label, microseconds, iters, ips, measurement_cycle)
@entries[group_label].last
end
# retrieve benchmark data for a particular label
def data_for group_label
@entries[group_label].collect do |report|
size = report.label.split(' ').last.to_i
microseconds_per_iters = 1000000.0 / report.ips.to_f
{label: size,
microseconds_per_iters: microseconds_per_iters,
ips: report.ips
}
end
end
# retrieve a summary of data for the benchmark report
def data
@entries.keys.map do |k|
key_data = data_for(k)
data = Hash[key_data.collect{|h| [h[:label], h[:microseconds_per_iters]]}]
{name: k, data: data}
end
end
end
end
end