# module Benchmark::Timing

### Public Class Methods

clean_env() click to toggle source

    # File lib/benchmark/timing.rb, line 31
    def self.clean_env
      # rbx
      if GC.respond_to? :run
        GC.run(true)
      else
        GC.start
      end
    end

mean(samples) click to toggle source

    # File lib/benchmark/timing.rb, line 3
    def self.mean(samples)
      sum = samples.inject(0) { |acc, i| acc + i }
      sum / samples.size
    end

resample_mean(samples, resample_times=100) click to toggle source

    # File lib/benchmark/timing.rb, line 20
    def self.resample_mean(samples, resample_times=100)
      resamples = []

      resample_times.times do
        resample = samples.map { samples[rand(samples.size)] }
        resamples << Timing.mean(resample)
      end

      resamples
    end

stddev(samples, m=nil) click to toggle source

    # File lib/benchmark/timing.rb, line 16
    def self.stddev(samples, m=nil)
      Math.sqrt variance(samples, m)
    end

variance(samples, m=nil) click to toggle source

    # File lib/benchmark/timing.rb, line 8
    def self.variance(samples, m=nil)
      m ||= mean(samples)

      total = samples.inject(0) { |acc, i| acc + ((i - m) ** 2) }

      total / samples.size
    end