3 ms·
I tried to do some quick benchmarks: % make hs Results: [25872791,24253954,21258158] make hs 6.53s user 3.99s system 245% cpu 4.282 total % m
by lgas 9y ago
I tried to do some quick benchmarks:
% make hs
Results: [25872791,24253954,21258158]
make hs 6.53s user 3.99s system 245% cpu 4.282 total
% make py
24029582
25343914
20814678
make py 22.37s user 0.11s system 99% cpu 22.593 total
You can see the code as tested here[0]. I am not an expert on either Haskell or Python performance, all I did was use -O for python3 and -O2 for GHC. This was on a 2.8 GHz Core i7 Macbook, FWIW.
Edit: Since 'contents' was unspecified I used one million random ints.
[0]: https://github.com/lgastako/compimp/tree/as-tested https://github.com/lgastako/compimp/tree/as-tested
- lgas 9y agoI 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 total
- vaibhavsagar 9y agoI took `contents` from here[0] but I like your random ints much better! [0]: https://github.com/vaibhavsagar/thursday-presentations/blob/6466b312ef07b4289c878356ddfcd6e4fba2f1d6/imperative-haskell/QuickSort.txt https://github.com/vaibhavsagar/thursday-presentations/blob/...
- etatoby 9y agoOh 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.
- lgas 9y agoI didn't expect similar execution time between them, not sure where you got that idea.
- Veedrac 9y ago$ 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 total
- lgas 9y agoVery nice.