Skip to content
This repository has been archived by the owner on Nov 20, 2017. It is now read-only.

droptheplot/factorials

Repository files navigation

Factorials

Gem Version

Ruby factorials as C extension.

Installation

Add this line to your application's Gemfile:

gem 'factorials'

And then execute:

$ bundle

Or install it yourself as:

$ gem install factorials

Usage

Factorial

10.factorial
# => 3628800

Double Factorial

10.double_factorial
# => 3840

Super Factorial

5.superfactorial
# => 34560

Benchmark

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)

TODO

  • Support very long long long integers.

Contributing

  1. Fork it (https://github.com/droptheplot/factorials/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.

About

Ruby factorials as C extension.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published