[Haskell-cafe] Why is Haskell so slow (comparing to Java/Scala)?
meburke at rocomai.com
meburke at rocomai.com
Wed Sep 20 19:46:32 UTC 2017
Thomas- You and Nick have been very helpful.
I tried to post this in reply to another post, but I got an error, so
I don't know if it went through. If this ends up as a double post,
please forgive me.
Now, the challenge is, given a set of objectives, how do you design a
system or program to get the same results as c/c++ in roughly the same
execution time.
If there was a modeling process (like UML for imperative OO languages)
for Haskell, we could compare models and see the differences.
NOTE: I typically use LISP or Racket, so Haskell is not my strong suite.
A good resource is "Everything That Linguists Have Always Wanted To
Know About Logic *But Were Ashamed to Ask" by McCawley. This has such
as good explanation of Lambda Calculus that it is worth wading through
the whole book.
Another NOTE: When using Symbolic Logic I use the Lukasiewicz notation
instead of the Principia notation. This made LISP, Racket and Scheme
really easy for me to think about. Haskell is still a little
different, but it helps there, too.
Mike Burke
Quoting Thomas DuBuisson <thomas.dubuisson at gmail.com>:
> To recap
>
> You claimed a 40ms measurement. If we use `for_` instead of `void $
> for` (for reasons mentioned earlier in the thread) and `-O2` when
> compiling we get just under 1 ms:
>
> ```
> time 876.2 μs (852.8 μs .. 896.9 μs)
> 0.994 R² (0.989 R² .. 0.998 R²)
> mean 838.4 μs (825.0 μs .. 855.5 μs)
> std dev 48.21 μs (36.91 μs .. 74.18 μs)
> variance introduced by outliers: 48% (moderately inflated)
> ```
>
> Cheers,
> Thomas
>
>
>
>
> On Wed, Sep 20, 2017 at 7:27 AM, Станислав Черничкин
> <schernichkin at gmail.com> wrote:
>> I've wrote simple Haskell benchmark program, which populated primitive
>> vector from vector package:
>>
>> import Data.Vector.Primitive.Mutable as P
>>
>> vectorBench :: Benchmark
>> vectorBench = bgroup "vector" [ primitive ]
>> where
>> primitive = bgroup "primitive" [ write1M ]
>> where
>> write1M = bench "write1M" $ nfIO $ do
>> v <- P.unsafeNew 1000000
>> void $ for [0..1000000 - 1] $ flip (P.unsafeWrite v) (1 :: Int)
>> return ()
>>
>> I use `unsafeNew` to skip memory initialization and `unsafeWrite` to skip
>> boundary checks, I guess it's fastest possible way to write something to
>> vector. My result was about 40 ms.
>>
>> 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?
>>
>>
>> --
>> Sincerely, Stanislav Chernichkin.
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
More information about the Haskell-Cafe
mailing list