开发者

Why is this not faster using parallel collections?

开发者 https://www.devze.com 2023-03-08 12:16 出处:网络
I just want开发者_开发技巧ed to test the parallel collections a bit and I used the following line of code (in REPL):

I just want开发者_开发技巧ed to test the parallel collections a bit and I used the following line of code (in REPL):

(1 to 100000).par.filter(BigInt(_).isProbablePrime(100))

against:

(1 to 100000).filter(BigInt(_).isProbablePrime(100))

But the parallel version is not faster. In fact it even feels a bit slower (But I haven't really measured that).

Has anyone an explanation for that?

Edit 1: Yes, I do have a multi-core processor

Edit 2: OK, I "solved" the problem myself. The implementation of isProbablePrime seems to be the problem and not the parallel collections. I replaced isProbablePrime with another function to test for primality and now I get an expected speedup.


Both with sequential and parallel ranges, filter will generate a vector data structure - a Vector or a ParVector, respectively.

This is a known problem with parallel vectors that get generated from range collections - transformer methods (such as filter) for parallel vectors do not construct the vector in parallel.

A solution for this that allows efficient parallel construction of vectors has already been developed, but was not yet implemented. I suggest you file a ticket, so that it can be fixed for the next release.

0

精彩评论

暂无评论...
验证码 换一张
取 消