<div dir="ltr"><div><div><div>(Just a little testing of the exciting new math lib.)<br></div><div><br></div>Is it currently normal that computing the mean of a big list is 10x slower compared to the (/ (apply + l) (length l)) method?<br>
<br></div>The math lib is very recent so I'm not entirely surprised, anyway. Most of the time seems to be due to GC.<br><br></div><div>E.g. (on command line Racket) :<br>#lang typed/racket<br><br>(require math)<br><br>
(: n Integer)<br>(define n 10000000)<br>(: l (Listof Integer))<br>(define l (build-list n (ë(x)(random 100))))<br><br>(: my-mean ((Listof Integer) -> Number))<br>(define (my-mean l)<br> (/ (apply + l) (length l)))<br>
<br>(time (mean l))<br>(time (my-mean l))<br><br>--> <br><br>cpu time: 3932 real time: 3931 gc time: 2848<br>495033609/10000000<br>cpu time: 408 real time: 406 gc time: 4<br>495033609/10000000<br><br><br>Cheers,<br></div>
Laurent<br></div>