💎 Ruby containing Rust 🦀 (thx. to rutie)
- Build in Ruby
- maintain all functionality in Ruby
- Optimize in Rust
-
translate performance sensitive operations into Rust
-
compare Ruby and Rust performance using
Benchmarker
-
- Fallback on Ruby
-
worst case, it's Ruby
-
wrap your Rust code in a default Ruby implimentation using
Fallbacker
-
- tour
rake main
rake primes:demo:benchmark {limit} {count}
rake primes:demo:fallback {limit} {count}
- compute primes
rake primes:ruby {limit}
rake primes:rust {limit}
- run tests
rake spec:run
- runs
rspec
andcargo test
- builds Rust code before running
rspec
- runs
- 🦀rustby🐝 made use of
Primes
as the example module around which to build - it contains two modules to compute primes
Primes::Alg::SieveOfAtkin
andPrimes::Alg::Naive
- Each module computes primes using a different algorithm
- each algorithm is provided in both Ruby and Rust via a computational class:
- while overkill for computing primes, this demonstrates the nesting pattern:
MyComputationalModule
MyComputationalModule::Ruby
MyComputationalModule::Rust
- args
{limit} - 💎Integer, 🦀u64
- compute all primes less than or equal to
- increase to stress test memory usage
{count} - 💎Integer, 🦀u64
- run the computation this many times
- increase to stress test computation speed
{alg_str} - 💎String
- select algorithm for computation
- can be:
sieve_of_atkin, soa, s
naive, n
rake primes:demo:benchmark
rake primes:demo:fallback
rake primes:ruby {limit} {alg_str}
rake primes:ruby:sieve_of_atkin {limit}
rake primes:ruby:naive {limit}
rake primes:rust {limit} {alg_str}
rake primes:rust:sieve_of_atkin {limit}
rake primes:rust:naive {limit}
rake primes:benchmark {limit} {count}
rake primes:benchmark:sieve_of_atkin {limit} {count}
rake primes:benchmark:naive {limit} {count}
The gem is available as open source under the terms of the MIT License.