File: factorial_hash.rb

package info (click to toggle)
ruby-distribution 0.7.3+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 624 kB
  • ctags: 379
  • sloc: ruby: 4,283; makefile: 7
file content (24 lines) | stat: -rw-r--r-- 554 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$:.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