From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Comparison of OCaml and MLton for numerics
Date: Thu, 31 May 2007 07:17:01 +0100 [thread overview]
Message-ID: <200705310717.01553.jon@ffconsultancy.com> (raw)
In-Reply-To: <5195a210705302250u6a9e5adey4ed857480f9e5cd8@mail.gmail.com>
On Thursday 31 May 2007 06:50:05 Yuanchen Zhu wrote:
> The performance numbers were as following:
>
> Ocaml (unsafe) : user: 39.674s, real: 41.356s
> MLton (safe): user: 17.981s, real: 21.968s
You may be interested to know that there are no optimizing SML compilers for
AMD64, which is a much better platform for numerical work:
http://www.ffconsultancy.com/languages/ray_tracer/results.html
OCaml is over 60% faster on this benchmark.
Having said that, I notice that twice as many people are downloading the x86
demos on my site compared to the x64.
> let hconvolve kern (img:t) r =
> let sup = Array.length kern - 1 in
> let img' = create (size img) in
> for y = 0 to height img - 1 do
> for x = 0 to width img - 1 do
> let s = ref 0.0 in
> for i = 0 to sup do
> let (kx, ky) = kern.(i) in
> s := !s +. ky *. getReflected img y (x + kx) 1.0 r
I can think of various ways to rearrange this that might help performance.
> The new running time is:
>
> Ocaml (unsafe) : user: 21.477s, real: 23.366s
What is the running time for safe OCaml?
> which is much in line with MLton:
>
> MLton (safe): user: 17.981s, real: 21.968s
What platforms and architectures did you benchmark on? May we have the code to
benchmark it ourselves?
> Although note that the MLton version has array-bound check enabled and
> used the two-line high order function version of hconvolve.
You might also try an FFT-based convolution if your filter is dense.
> So the moral of the story: To use Ocaml for numerically intensive
> work, code in C style in the inner loops.
Absolutely.
> This brings me to the next question: is there any plan to implement
> type specialization optimization for ocamlopt? For numerics, this is
> really crucial if you want write both in an elegant functional style
> and get good performance. Also, I remember reading somewhere that the
> current code base of Ocaml is ill-suited for implementing this kind of
> optimization. May I ask what exactly needs to be done to the current
> code base in order to support that? I have some compiler-writing
> background and this sounds like an interesting project to work in my
> past time.
Writing OCaml programs that generate OCaml programs is by far your best bet
here. We use a replacement standard library that uses autogenerated code to
eliminate boxing and perform unrolling and type specialization where
possible.
As I can autogenerate my code, I would much rather the OCaml developers
concentrated on things that I cannot get around, like the lack of a 32-bit
float storage type and a more efficient internal representation of complex
numbers.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?e
next prev parent reply other threads:[~2007-05-31 6:22 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-31 5:50 Yuanchen Zhu
2007-05-31 6:17 ` Jon Harrop [this message]
2007-05-31 6:32 ` [Caml-list] " skaller
2007-05-31 7:31 ` Yuanchen Zhu
2007-05-31 9:08 ` Jon Harrop
2007-05-31 9:22 ` Yuanchen Zhu
2007-05-31 10:27 ` Jon Harrop
2007-05-31 21:30 ` Alain Frisch
2007-06-01 1:22 ` skaller
2007-06-01 1:36 ` Erik de Castro Lopo
2007-06-01 2:21 ` skaller
2007-06-01 2:49 ` Erick Tryzelaar
2007-06-01 3:05 ` skaller
2007-06-01 5:30 ` Alain Frisch
2007-06-01 5:39 ` Jon Harrop
2007-06-01 6:36 ` Yuanchen Zhu
2007-06-01 8:09 ` skaller
2007-06-01 8:53 ` Richard Jones
2007-06-01 8:59 ` Richard Jones
2007-06-01 9:22 ` Stephan Tolksdorf
2007-06-01 9:49 ` Richard Jones
2007-06-01 9:32 ` Stephan Tolksdorf
2007-06-01 10:02 ` skaller
2007-06-01 11:29 ` Yaron Minsky
2007-06-01 11:43 ` Erik de Castro Lopo
2007-06-01 11:58 ` Jon Harrop
2007-06-01 13:49 ` Julien Signoles
2007-06-01 14:18 ` Stephen Weeks
2007-06-01 14:43 ` Julien Signoles
2007-06-01 14:57 ` Brian Hurt
2007-06-01 15:40 ` Alain Frisch
2007-06-01 15:58 ` Brian Hurt
2007-06-01 16:25 ` Markus Mottl
2007-06-01 16:47 ` Jon Harrop
2007-06-01 23:26 ` skaller
2007-06-01 23:49 ` Brian Hurt
2007-06-02 3:26 ` skaller
2007-06-01 12:40 ` Erik de Castro Lopo
2007-06-01 13:56 ` Julien Signoles
2007-06-01 11:49 ` David MENTRE
2007-06-01 14:41 ` skaller
2007-06-01 16:52 ` Jon Harrop
2007-06-01 23:33 ` skaller
2007-06-01 16:14 ` Markus Mottl
2007-06-01 16:46 ` Jon Harrop
2007-06-01 17:13 ` Jon Harrop
2007-06-04 14:03 ` Mike Furr
2007-06-04 14:39 ` Jon Harrop
2007-06-04 15:33 ` Mike Furr
2007-06-04 18:08 ` skaller
[not found] ` <9d3ec8300706041518y115d22bdsa120d4010261d841@mail.gmail.com>
2007-06-04 22:19 ` Fwd: " Till Varoquaux
2007-06-04 23:40 ` Jon Harrop
2007-06-05 2:24 ` skaller
2007-06-04 22:44 ` Pierre Etchemaïté
2007-06-05 1:42 ` Jon Harrop
2007-06-05 10:30 ` Jon Harrop
2007-06-10 12:10 ` Jon Harrop
2007-06-10 12:58 ` skaller
2007-06-01 14:15 ` Stephen Weeks
2007-06-01 14:37 ` Brian Hurt
2007-06-01 14:39 ` Eric Cooper
2007-05-31 9:24 ` Yuanchen Zhu
2007-05-31 10:25 ` Loup Vaillant
2007-05-31 10:30 ` Jon Harrop
2007-05-31 12:12 ` skaller
2007-05-31 7:11 ` Daniel Bünzli
2007-05-31 15:15 ` Christophe Raffalli
2007-05-31 15:23 ` Jon Harrop
2007-05-31 15:35 ` Christophe Raffalli
[not found] ` <604682010705310923o5a1ee0eiee5ae697da9d3c60@mail.gmail.com>
2007-05-31 20:14 ` Stephen Weeks
2007-05-31 15:16 ` Christophe Raffalli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200705310717.01553.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox