Class: DerailedBenchmarks::StatsForFile
- Defined in:
- lib/derailed_benchmarks/stats_for_file.rb
Overview
A class for reading in benchmark results and converting them to numbers for comparison
Example:
puts `cat muhfile.bench.txt`
9.590142 0.831269 10.457801 ( 10.0)
9.836019 0.837319 10.728024 ( 11.0)
x = StatsForFile.new(name: "muhcommit", file: "muhfile.bench.txt", desc: "I made it faster", time: Time.now)
x.values #=> [11.437769, 11.792425]
x.average # => 10.5
x.name # => "muhfile"
Instance Attribute Summary collapse
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#short_sha ⇒ Object
readonly
Returns the value of attribute short_sha.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #average ⇒ Object
- #call ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(file:, name:, desc: "", time:, short_sha: nil) ⇒ StatsForFile
constructor
A new instance of StatsForFile.
- #median ⇒ Object
Constructor Details
#initialize(file:, name:, desc: "", time:, short_sha: nil) ⇒ StatsForFile
Returns a new instance of StatsForFile.
21 22 23 24 25 26 27 28 29 |
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 21 def initialize(file:, name:, desc: "", time: , short_sha: nil) @file = Pathname.new(file) FileUtils.touch(@file) @name = name @desc = desc @time = time @short_sha = short_sha end |
Instance Attribute Details
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
19 20 21 |
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 19 def desc @desc end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 19 def name @name end |
#short_sha ⇒ Object (readonly)
Returns the value of attribute short_sha.
19 20 21 |
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 19 def short_sha @short_sha end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
19 20 21 |
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 19 def time @time end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
19 20 21 |
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 19 def values @values end |
Instance Method Details
#average ⇒ Object
47 48 49 |
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 47 def average @average.to_f end |
#call ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 31 def call load_file! return if values.empty? @median = (values[(values.length - 1) / 2] + values[values.length/ 2]) / 2.0 @average = values.inject(:+) / values.length end |
#empty? ⇒ Boolean
39 40 41 |
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 39 def empty? values.empty? end |
#median ⇒ Object
43 44 45 |
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 43 def median @median.to_f end |