I was playing around a little more and I noticed that stack sets the following
ghc-options by default:
-threaded -rtsopts -with-rtsopts=-N
which I assumed explained some of the speedup, so I disabled them and got a
reduction to 99% cpu as expected, but unexpectedly the single threaded version
was about twice as fast: % make hs
Results: [24605537,25150983,21576960]
make hs 3.13s user 0.07s system 99% cpu 3.211 totalHaskell threaded runtime can have poorer performances than the non-threaded one on single threaded programs.
Depending on your problem you can actually lose performance with a multi-threaded app due to the context switching overhead.
$ time make hs
Results: [24639155,24977202,20874958]
make hs 8.39s user 5.93s system 322% cpu 4.435 total
$ time make py
24894022
25787638
21979201
make py 14.33s user 0.02s system 99% cpu 14.353 total
$ time make py PYTHON=pypy3
25059732
25318854
21254890
make py PYTHON=pypy3 4.02s user 0.06s system 99% cpu 4.082 totalVery nice.
Oh come on, how can you expect similar execution time between a compiled language like Haskell and an interpreter like Python? I would be very surprised if the latter was not several times slower, purity or not.
If anything, you may want to compare compiled Haskell code to an impure, imperative language that is also strongly typed, compiled to machine language, and garbage collected, like Go.
I didn't expect similar execution time between them, not sure where you got that idea.
Re:Imperative Haskell
by vaibhavsagar on Wednesday May 31, 2017 @04:11AM
(#14451037)
I took `contents` from here[0] but I like your random ints much better!
[0]: https://github.com/vaibhavsagar/thursday-presentations/blob/...
Edit: Since 'contents' was unspecified I used one million random ints.
[0]: https://github.com/lgastako/compimp/tree/as-tested