Parallel processing with ruby
If you want to optimise your code with parallel processing in ruby you can use very useful gem Parallel.
Gem Parallel can use all your CPUs for any calculation ( math/map-reduce processing) or downloads/uploads.
Let’s test it.
We want to calculate sum of prime number in array of any numbers.
In other word, we have array [1,2,3,4,5]. We need to find prime numbers ([1,2,3,5]). And then need to calculate sum (11). Array of numbers from 1 to 5 is very small to feel differents. I will use three arrays in a row with numbers from 1 to 60000, 50000 or 10000.
You can see code below.
I know that is_prime? function is not optimised and better to user prime library for it. But for example I use it.
If we run this code in console, we will see results:
Pretty cute, yeah?