Sha256: 99e63e1e612fc706302dc38234f169517b1f1852615d8f5db6af52c0d1e43b83

Contents?: true

Size: 815 Bytes

Versions: 6

Compression:

Stored size: 815 Bytes

Contents

#!/usr/bin/env ruby
require 'decimal'
require 'bigdecimal'
require 'dec_number'
require 'benchmark'
include Benchmark
n = 123.58132134
m = Math::PI
bm(6) do |x|
  x.report("dec_number") do
    a = n.to_dec_number
    b = m.to_dec_number
    100_000.times do
      ((a * b + DecNumber.new(rand().to_s) - b / a) ** b).to_s
    end
  end
  x.report("decimal") do
    a = Decimal.new n.to_s
    b = Decimal.new m.to_s
    100_000.times do
      ((a * b + Decimal.new(rand().to_s) - b / a) ** b).to_s
    end
  end
  x.report("bigdecimal") do
    a = BigDecimal.new n.to_s
    b = BigDecimal.new m.to_s
    100_000.times do
      (a * b + BigDecimal.new(rand().to_s) - b / a).to_s
    end
  end
  x.report("float") do
    a = n
    b = m
    100_000.times do
      ((a * b + rand() - b / a) ** b).to_s
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dec_number-0.2.0 ext/dec_number/bench.rb
dec_number-0.1.6 ext/dec_number/bench.rb
dec_number-0.1.5 ext/dec_number/bench.rb
dec_number-0.1.4 ext/dec_number/bench.rb
dec_number-0.1.3 ext/dec_number/bench.rb
dec_number-0.1.2 ext/dec_number/bench.rb