File: power.rb

package info (click to toggle)
ruby-distribution 0.8.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: ruby: 4,535; makefile: 10
file content (27 lines) | stat: -rw-r--r-- 539 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'bench_press'
require 'bigdecimal'
extend BenchPress

name 'Float vs Rational power'
author 'Claudio Bustos'
date '2011-02-02'
summary "
On ruby, the maximum size of a float is #{Float::MAX}.
With Rational, we can raise to integer numbers and surpass Float maximum.
What is the speed reduction using Rational?"

reps 1000 # number of repetitions
int = 10
rat = 10.quo(1)
bd = BigDecimal('10')
measure 'Using float pow' do
  int**307
end

measure 'Using rational' do
  rat**307
end

measure 'Using big decimal pow' do
  bd**307
end