Sha256: c3fbb134d575f41db9f3980a92b4248d8adc30dbad1e3216a2afe0c88cd497c7
Contents?: true
Size: 512 Bytes
Versions: 3
Compression:
Stored size: 512 Bytes
Contents
require "standard_deviation" require "benchmark" require 'bigdecimal' class Array def stdev_ruby total = inject :+ mean = total.to_f / size variance = inject(0) { |variance, value| variance + (value - mean) ** 2 } / (size - 1) Math.sqrt(variance) end end n = 50 values = (1..10_000).map { |value| BigDecimal.new [value, (rand * 10000000000).to_i].join(".") } Benchmark.bm do |b| b.report do n.times { values.stdev } end b.report do n.times { values.stdev_ruby } end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
standard_deviation-1.0.3 | benchmark/bigdecimal.rb |
standard_deviation-1.0.2 | benchmark/bigdecimal.rb |
standard_deviation-1.0.1 | benchmark/bigdecimal.rb |