Class: DerailedBenchmarks::StatsForFile
- Defined in:
- lib/derailed_benchmarks/stats_in_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.
-
#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
-
#initialize(file:, name:, desc: "", time:) ⇒ StatsForFile
constructor
A new instance of StatsForFile.
- #median ⇒ Object
Constructor Details
#initialize(file:, name:, desc: "", time:) ⇒ StatsForFile
Returns a new instance of StatsForFile.
21 22 23 24 25 26 27 28 |
# File 'lib/derailed_benchmarks/stats_in_file.rb', line 21 def initialize(file:, name:, desc: "", time: ) @file = Pathname.new(file) FileUtils.touch(@file) @name = name @desc = desc @time = time end |
Instance Attribute Details
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
19 20 21 |
# File 'lib/derailed_benchmarks/stats_in_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_in_file.rb', line 19 def name @name end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
19 20 21 |
# File 'lib/derailed_benchmarks/stats_in_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_in_file.rb', line 19 def values @values end |
Instance Method Details
#average ⇒ Object
41 42 43 |
# File 'lib/derailed_benchmarks/stats_in_file.rb', line 41 def average @average.to_f end |
#call ⇒ Object
30 31 32 33 34 35 |
# File 'lib/derailed_benchmarks/stats_in_file.rb', line 30 def call load_file! @median = (values[(values.length - 1) / 2] + values[values.length/ 2]) / 2.0 @average = values.inject(:+) / values.length end |
#median ⇒ Object
37 38 39 |
# File 'lib/derailed_benchmarks/stats_in_file.rb', line 37 def median @median.to_f end |