[Haskell-cafe] Why is Haskell so slow (comparing to Java/Scala)?

Florian Weimer fw at deneb.enyo.de
Mon Oct 23 21:49:46 UTC 2017


* Станислав Черничкин:

> I wrote similar program in Scala:
>
> for (_ <- 1 to 5) {
>   val start = System.currentTimeMillis()
>   val a = new Array[Long](1000000)
>   for (i <- 0 until 1000000) {
>     a(i) = 1L
>   }
>   val end = System.currentTimeMillis()
>   println(s"${end - start} ms")
> }
>
> I skip neither boundary checks nor memory initialization, I also used
> generic array here (suitable for any types of objects, not just for
> primitive types), so I expected longer run time. But what I got was
> shocking:
>
> 7 ms
> 3 ms
> 2 ms
> 1 ms
> 2 ms
>
> This program runs 20-40 times faster than Haskell after warm-up. 20-40
> times, Carl! Why is Haskell soo slooooow? How can it be?

It is possible that Hotspot optimizes away most of the code, perhaps
even the entire array allocation.  Meaningful benchmarking is quite
difficult due to such effects.

Does the execution time even change if you increase the number of
iterations (inner or outer)?


More information about the Haskell-Cafe mailing list