|
|
|
|
|
by zoffix222
3017 days ago
|
|
I like concurrency in Rakudo Perl 6. (https://docs.perl6.org/language/concurrency) Especially the .hyper method that turns a regular sequence into hyper sequence that gets processed in parallel. First 5000 prime numbers: # single-thread, takes 14.893s
put ^∞ .grep(*.is-prime).head: 5000
# multi-threaded, takes 8.853s on my 2-core box
put ^∞ .hyper.grep(*.is-prime).head: 5000
|
|
For parallelism as what you describe, D instead has approximately the same thing. There's a `parallel` function in the standard library that works on any range (i.e. any iterable). You basically instead of doing
do and it works like your Perl example.If you want it more functionalish, without writing out the loop, you can use `taskPool.map` instead of ordinary `map` for the same effect. More details:
stdlib: https://dlang.org/phobos/std_parallelism.html
Programming in D chapter on parallelism: http://ddili.org/ders/d.en/parallelism.html