jbdoderlein / BetterOCaml

A small but efficient, intuitive and responsive OCaml IDE right in your browser! Ships OCaml v5.1.1, interpreter by your browser (so it works offline!), compiled with js_of_ocaml.
https://jbdoderlein.github.io/BetterOCaml/
Apache License 2.0
38 stars 8 forks source link

Performance difference between v4.11 and v5.1+ ?? (on a tiny snippet of recursive OCaml code) #76

Open Naereen opened 1 month ago

Naereen commented 1 month ago

Hi there, I recently tested on your version the latest v5.1+ version, with the following piece of code:

let rec binom k n =
    if k < 0 || k > n then 0
    else if k = 0 || k = n then 1
    else binom k (n - 1) + binom (k - 1) (n - 1)
;;

let debut = Sys.time() in
let b_15_30 = binom 15 30 in
let fin = Sys.time() in
Printf.printf "binom 15 30 a pris %g secondes\n" (fin -. debut);
b_15_30;;

It gives about 3.5 seconds on http://ocaml.besson.link/, hosting the version 4.14.1 of BetterOCaml, and about 16.117 seconds on your most recent version on https://jbdoderlein.github.io/BetterOCaml/?version=5.1.1.

Is there any reason for such a large difference? I don't have a v5+ OCaml toplevel installed locally and won't install it now, so I can't test offline, but the difference seems huge.

Thanks for the answer, if you have any idea why :smile: !