Ruby factorials as C extension.
Add this line to your application's Gemfile:
gem 'factorials'
And then execute:
$ bundle
Or install it yourself as:
$ gem install factorials
10.factorial
# => 3628800
10.double_factorial
# => 3840
5.superfactorial
# => 34560
Conditions:
Benchmark.bmbm(7) do |x|
int = 100_000
x.report('Factorial (Ruby)') do
(1..int).inject(:*)
end
x.report('Factorial (C)') do
int.factorial
end
end
Results:
Rehearsal ----------------------------------------------------
Factorial (Ruby) 4.710000 2.320000 7.030000 ( 7.495018)
Factorial (C) 0.000000 0.000000 0.000000 ( 0.000156)
------------------------------------------- total: 7.030000sec
user system total real
Factorial (Ruby) 4.720000 2.400000 7.120000 ( 7.787638)
Factorial (C) 0.000000 0.000000 0.000000 ( 0.000131)
- Support very long long long integers.
- Fork it (https://github.com/droptheplot/factorials/fork)
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
The gem is available as open source under the terms of the MIT License.