3 ms·
Haskell is also really fast. On most Stack Overflow questions asking "why is this Haskell program slow", there's often a detailed answer with an implemention th
by runeks 10y ago
Haskell is also really fast. On most Stack Overflow questions asking "why is this Haskell program slow", there's often a detailed answer with an implemention that's about as fast as -- or even faster than -- C:
http://stackoverflow.com/questions/42771348/why-is-haskell-so-slow-compared-to-c-for-fibonacci-sequence http://stackoverflow.com/questions/42771348/why-is-haskell-s...
http://stackoverflow.com/questions/6964392/speed-comparison-with-project-euler-c-vs-python-vs-erlang-vs-haskell http://stackoverflow.com/questions/6964392/speed-comparison-...
http://stackoverflow.com/questions/29875886/haskell-why-does-int-performs-worse-than-word64-and-why-my-program-is-far-slow http://stackoverflow.com/questions/29875886/haskell-why-does...
- Johnny_Brahms 10y agoNone of those are very good examples. They spend a lot of time optimizing already dead-slow algorithms, and they end up with an optimized dead-slow haskell version that is faster than the non-optimized dead-slow C version. Not very impressive. I thought I would implement some naive versions: For he second link, I just whipped up this naive in chez scheme, and it runs in 0.5s, and that should really be the baseline: https://pastebin.com/JXGLA4TR https://pastebin.com/JXGLA4TR Incidentally this seems to be on par with the fastest haskell version posted that does not use precomputed primes for factorisation. It could be made a lot faster by using only primes, but I couldn't be bothered. And I doubt you will find a haskell version that gets the longest collatz-sequence that is faster than this: https://pastebin.com/FAdiHA3X https://pastebin.com/FAdiHA3X (0.01s using gcc -O2). Yet again, a simple algorithm, but this time with bolted-on memoization. Edit: The first link contains the most naive and slow fibonacci function. It might be mathematically elegant, but it is dirt slow. (define (fib n) (let loop ([n n] [a 0] [b 1]) (if (zero? n) b (loop (- n 1) b (+ a b))))) That one takes 0.1s calculating the 100.000th fibonacci number, and there are even faster ways.