Sha256: 0d371d6dca0b22bf14741688c2cb229f791d343f8f2b21def8500fb9555f8601

Contents?: true

Size: 904 Bytes

Versions: 1

Compression:

Stored size: 904 Bytes

Contents

# Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
# 
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

module Bench

  module Stats

    def self.sum(samples)
      samples.inject(0, :+)
    end

    def self.mean(samples)
      sum(samples) / samples.size
    end

    def self.sample_variance(samples)
      m = mean(samples)
      sum = samples.inject(0) { |a, i| a + (i - m)**2 }
      sum / (samples.length - 1).to_f
    end

    def self.standard_deviation(samples)
      Math.sqrt(sample_variance(samples))
    end

    def self.range(samples)
      samples.max - samples.min
    end

    def self.format_percent(p)
      "#{(p * 100).round(2)}%"
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bench9000-0.1 lib/bench9000/stats.rb