Module: Benchmark::Timing
- Defined in:
- lib/benchmark/timing.rb
Overview
Perform calculations on Timing results.
Constant Summary collapse
- MICROSECONDS_PER_SECOND =
Microseconds per second.
1_000_000
Class Method Summary collapse
-
.clean_env ⇒ Object
Recycle used objects by starting Garbage Collector.
-
.mean(samples) ⇒ Float
Calculate (arithmetic) mean of given samples.
-
.stddev(samples, m = nil) ⇒ Float
Calculate standard deviation of given samples.
-
.variance(samples, m = nil) ⇒ Float
Calculate variance of given samples.
Class Method Details
.clean_env ⇒ Object
Recycle used objects by starting Garbage Collector.
35 36 37 38 39 40 41 42 |
# File 'lib/benchmark/timing.rb', line 35 def self.clean_env # rbx if GC.respond_to? :run GC.run(true) else GC.start end end |
.mean(samples) ⇒ Float
Calculate (arithmetic) mean of given samples.
10 11 12 13 |
# File 'lib/benchmark/timing.rb', line 10 def self.mean(samples) sum = samples.inject(:+) sum / samples.size end |
.stddev(samples, m = nil) ⇒ Float
Calculate standard deviation of given samples.
30 31 32 |
# File 'lib/benchmark/timing.rb', line 30 def self.stddev(samples, m=nil) Math.sqrt variance(samples, m) end |
.variance(samples, m = nil) ⇒ Float
Calculate variance of given samples.
18 19 20 21 22 23 24 |
# File 'lib/benchmark/timing.rb', line 18 def self.variance(samples, m=nil) m ||= mean(samples) total = samples.inject(0) { |acc, i| acc + ((i - m) ** 2) } total / samples.size end |