File: factorial_hash.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 (23 lines) | stat: -rw-r--r-- 565 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
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
require 'bench_press'
require 'distribution'
extend BenchPress

name 'calculate factorial vs looking on a Hash'
author 'Claudio Bustos'
date '2011-01-31'
summary "
Is better create a lookup table for factorial or just calculate it?
Distribution::MathExtension::SwingFactorial has a lookup table
for factorials n<20
"

reps 1000 # number of repetitions

measure 'Lookup' do
  Math.factorial(19)
end

measure 'calculate' do
  Distribution::MathExtension::SwingFactorial.naive_factorial(19)
end