Testing running times Elm vs Haskell

First of all, this is made just for fun. The results are mainly as expected and they prove nothing about the real performances.

Test 1 Elm-code at rosettacode
Test code with modified limits

run in browser elm at Ellie site
The primes up to 320 000 are: 2, 3, 5, 7, 11, 13,
…, 319931, 319937, 319967, 319973, 319981, 319993.
Found 27608 primes to 320000 in 173 milliseconds.

Test 2 run in browser local compiled elm to JavaScript
The primes up to 320 000 are: 2, 3, 5, 7, 11, 13,…,319849, 319883, 319897, 319901, 319919, 319927, 319931, 319937, 319967, 319973, 319981, 319993.
Found 27608 primes to 320000 in 113 milliseconds.

Test 3 run at local file compiled with GHC
,99709,99713,99719,99721,99733,99761,99767,99787,99793,99809,99817,99823,99829,99833,99839,99859,99871,99877,99881,99901,99907,99923,
99929,99961,99971,99989,99991]
The number of primes up to 320000 is 27608
Found 27608 to 320000 in 6 milliseconds.
~/myhaskell$

Test 4 run in browser at Playground
modifed limits
copy from the original code at rosettacode

19927,19937,19949,19961,19963,19973,19979,19991,19993,19997]
The number of primes up to 320000 is 27608
Found 27608 to 320000 in 3 milliseconds.

Test 5
run in ghci
The number of primes up to 320000 is 27608
Found 27608 to 320000 in 807 milliseconds.
ghci> :q

1 Like

Is it possible to measure Elm but with optimize level 2?

1 Like

I’m glad you asked that because I didn’t know before anything about elm optimizing level 2.
So I did the following:

jarmo$ npx elm-optimize-level-2 calculus/Primes320k.elm
Need to install the following packages:
  elm-optimize-level-2@0.3.5
Ok to proceed? (y) y
DeprecationWarning: 'createIdentifier' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead.
Compiled, optimizing JS...
.
.
Success!

   Primes320k.elm ───> elm.js
  • continued to minimize elm.js with this:
jarmo$ uglifyjs elm.js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' | uglifyjs --mangle --output optimlevel2.js

-rw-r--r--   1 jarmo   150331  7 Mar 14:34 elm.js
-rw-r--r--   1 jarmo    28833  7 Mar 14:40 optimlevel2.js

My local test results

  • with elm.min.js
    Found 27608 primes to 320000 in 122 milliseconds.

  • with elm.js optimized level 2 and minimized
    Found 27608 primes to 320000 in 105 milliseconds.

Summary: Slightly improved with optimize level 2 :smiley:

2 Likes

there is a flag for speed also - don’t think this will change much but who knows :wink:

I’ll return as soon I have tested with speed flag.
Meanwhile, I tested with the optimized elm.js vs additionally minimizes js-file.
Result: solely optimized 107 ms vs additionally minimized 105 ms.
Reason, why I reduced upper limit from one million to 320,000:

The program is stuck after 1 Million primes shown, not showing the calculation times and must be forced with Ctrl+C to stop. Perhaps, a better measure is testing as near as possible to the critical limit somewhere in the range 320,000 to 1 Mio .

At last, elm-optimize-level2 is still an experimental package.

A fairer comparison might be to use GHCjs or the newer GHC backends to compile and run it in the browser on the same computer (I guess you did run it natively right?).

I’m a total newbie in haskell, thus have not yet used ghcjs and didn’t know even that there is a haskell to js compiler.
Well, if I’ll succeed to install and to initialize ghcjs and make an output app.js, is it included and used by frontend html exactly in the same way as in case of the elm-compiled js-file?

to be honest it’s been years since I last tried GHCjs (congrats for getting it up and running - this used to be quiet a feat) - but yes as far as I remember it should run as is

I found the Quick-start instruction but…
too many alternatives, I’ll skip that!

I have just run more speed tests, this time all were tested with finding primes up to 1 million.
Here are the test results.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.