PrimeLib
This gem generates a table of the product of N prime numbers. Current version aims to improve its performance on prime numbers retrieval.
Installation
Gemfile:
gem 'prime_lib', '~> 0.1.0'
Usage (in terminal)
> puts PrimeLib::GeneratorProduct.new(10).to_table
What I've done
Optimization of prime generation based on Sieve of Eratosthenes algorithm
Currently my implementation runs slightly faster[1] than sieve generator of Ruby 2.0 Prime lib[2] which has been greatly improved 6 month ago by Yugui[3].
[1] Ruby Lib takes roughly 1 sec to calculate 200,000 primes, my lib takes 0.6 secs
[2] https://github.com/ruby/ruby/blob/trunk/lib/prime.rb
[3] https://github.com/ruby/ruby/commit/def83bff91d59fa5fdd1898f903f9000ad1dbe13#diff-cb376f8d9ff85c3dbf97cd71a7463898To maximize performance gain I decided to run on C code
PrimeLib::Generator.new(n_samples, engine: PrimeLib::Generator::SieveOfEratosthenesC.new).to_a
Known issues:
- Ruby Inline C compiler throws some[1] warnings I should optimize, meanwhile I've not experienced any trouble (tested till 20_000_000 primes)
[1] "left-hand operand of comma expression has no effect", "passing argument 3 of ‘rb_ary_store’ makes integer from pointer without a cast"