4 ms·
Why is Haskell so slow at this? As far as I can tell, my Perl implementation at http://www.perlmonks.org/?node_id=276112 http://www.perlmonks.org/?node_id=2761
by btilly 12y ago
Why is Haskell so slow at this?
As far as I can tell, my Perl implementation at http://www.perlmonks.org/?node_id=276112 http://www.perlmonks.org/?node_id=276112 is doing something similar with similar amounts of laziness and no optimizations build it. Yet I can produce the first 50,000 primes in the time that this takes to produce the first 10,000. And nobody uses Perl for its speed!
- delluminatus 12y agoI'm not sure, maybe it's just the overhead of having so many function calls and Set accesses? My guess is that the Haskell one could be made quite a bit more efficient if you used a low-level mutable array. To add another benchmarking data point, I have a simple sieve of Eratosthenes written in Nim using an array that can generate 10,000 primes in less than a millisecond.
- deleted 12y ago[deleted]
- btilly 12y agoThat is why I compared to an implementation in Perl that was likewise making lots of excess function calls and storing things very inefficiently. This was as close to apples to apples as I could get without putting much energy forward. Perl gets a lot faster if you sieve blocks at a time, using vec() to manipulate bit arrays. And I'm not surprised that an actually efficient language would be massively faster.