module Benchmark::Timing
def self.add_second(t, s)
def self.add_second(t, s) t + (s * MICROSECONDS_PER_SECOND) end
def self.add_second(t, s)
def self.add_second(t, s) t + s end
def self.clean_env
def self.clean_env # rbx if GC.respond_to? :run GC.run(true) else GC.start end end
def self.mean(samples)
-
(Float)
- Mean of given samples.
Parameters:
-
samples
(Array
) -- Samples to calculate mean.
def self.mean(samples) sum = samples.inject(:+) sum / samples.size end
def self.now
def self.now Process.clock_gettime Process::CLOCK_MONOTONIC, :float_microsecond end
def self.now
def self.now Time.now end
def self.stddev(samples, m=nil)
-
(Float)
- standard deviation of given samples.
Parameters:
-
m
(Float
) -- Optional mean (Expected value). -
samples
(Array
) -- Samples to calculate standard deviation.
def self.stddev(samples, m=nil) Math.sqrt variance(samples, m) end
def self.time_us(before, after)
def self.time_us(before, after) after - before end
def self.time_us(before, after)
def self.time_us(before, after) (after.to_f - before.to_f) * MICROSECONDS_PER_SECOND end
def self.variance(samples, m=nil)
-
(Float)
- Variance of given samples.
Parameters:
-
m
(Float
) -- Optional mean (Expected value).
def self.variance(samples, m=nil) m ||= mean(samples) total = samples.inject(0) { |acc, i| acc + ((i - m) ** 2) } total / samples.size end