Version française
Home     About     Download     Resources     Contact us    
Browse thread
Comparison of OCaml and MLton for numerics
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Yuanchen Zhu <yzhu@f...>
Subject: Re: [Caml-list] Comparison of OCaml and MLton for numerics
>
> You are doing all this computation in your inner loop unnecessarily:
>
> let getReflected (img:t) y x yr xr =
>   let w = width img and h = height img in
>     if x >= 0 && x < w && y >= 0 && y < h then
>       img.(y).(x)
>     else
>       let x = abs x and y = abs y in
>       let xx = x/w and x' = x mod w and yy = y/h and y' = y mod h in
>       let x',xr = if xx mod 2 = 0 then (x',1.0) else (w - 1 - x',xr) in
>       let y',yr = if yy mod 2 = 0 then (y',1.0) else (h - 1 - y',yr) in
>         img.(y').(x') *. xr *.yr
>
> Hoist as much as you can from the inner loop and this program will run much
> faster in any language.

Yes, I am aware of the inefficiency here. Although because of branch
prediction on modern CPUs, the actual running time overhead would not
be that big.

My point, however, is that MLton and OCaml are being fed the same
code, and if OCaml performs specializing and proper inlining, it will
get almost twice its current performance.