From: Jon Harrop <jdh30@cam.ac.uk>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Functors
Date: Mon, 3 May 2004 19:41:46 +0100 [thread overview]
Message-ID: <200405031941.46770.jdh30@cam.ac.uk> (raw)
In-Reply-To: <Pine.LNX.4.43.0405031800321.15994-100000@pc8-119.lri.fr>
On Monday 03 May 2004 17:02, Julien Signoles wrote:
> As far as I test ocamldefun, performance improvement is very dependent of
> the application. Mainly, the defunctorized code is generally much more
> efficient than the code with functors if
> (1) some functions are not inlined due to functors; and
> (2) these functions are called very often.
> Generally, in the others case, the defunctorization do not improve
> performance a lot.
Absolutely, but it can result in a huge performance increase in some cases.
Although these cases may seem to be insignificant to most people round these
parts, I believe they would be a make-or-break for someone considering ocaml
for numerical work. The most obvious example would be to use functors to
partially specialise code for a primitive vector or geometric type. When I
did something equivalent in C++ using templates I saw a 2-3 times performance
improvement. I think it would be a shame if people had to resort to using
"cat" to build their ocaml source files before compiling...
> Some SML compilers include a defunctorizer... But, in a lot of cases,
> functors do not reduce performance a lot (as explained above). Morever,
> static analysis tools do not generally correctly work on functorized
> programs: so a source-to-source defunctorizer as ocamldefun can be used
> by these tools while a defunctorizer directly included in the compiler
> cannot. So i'm not sure including a defunctorizer in the compiler is a
> good thing...
I didn't mean including the defunctorizor in the compiler, just the
functionality which it provides. Perhaps I am mistaken, but can these
optimisations not be done after all of the analysis, as a relatively simple
extension to the current inlining optimisations?
I was afraid that the ocamldefun example might be out of date so I wrote my
own little version (see end). To my surprise, this example runs 15-18 times
slower when generated via a functor! I'd be interested to hear if other
people get similar results.
Cheers,
Jon.
module type FUNC = sig val f : int -> int -> int end
module Func : FUNC = struct let f a b = a / b end
module FuncFunc = functor (F : FUNC) -> struct let f = F.f end
module MyFunc = FuncFunc (Func)
let f1 a b = a / b
let _ =
let t = Unix.gettimeofday () in
for i=0 to 1000000000 do
ignore (f1 12345 8);
done;
print_string ("Same compilation unit took "^(string_of_float
((Unix.gettimeofday ()) -. t)));
print_newline ();
let t = Unix.gettimeofday () in
for i=0 to 1000000000 do
ignore (MyFunc.f 12345 8);
done;
print_string ("Same compilation unit took "^(string_of_float
((Unix.gettimeofday ()) -. t)));
print_newline ();
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2004-05-03 18:42 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-02 9:12 Jon Harrop
2004-05-02 10:24 ` Martin Jambon
2004-05-02 13:34 ` Jon Harrop
2004-05-02 14:12 ` skaller
2004-05-02 16:49 ` Jon Harrop
2004-05-03 0:20 ` skaller
2004-05-03 14:43 ` Jacques Carette
2004-05-03 16:09 ` Alain.Frisch
2004-05-03 18:53 ` Jacques Carette
2004-05-03 19:17 ` [Caml-list] Mathematica Jon Harrop
2004-05-03 22:51 ` [Caml-list] Functors Alain.Frisch
2004-05-03 16:02 ` Julien Signoles
2004-05-03 18:41 ` Jon Harrop [this message]
2004-05-04 7:25 ` Jean-Christophe Filliatre
2004-05-05 8:15 ` Julien Signoles
2004-05-05 20:41 ` brogoff
2004-05-06 11:16 ` Jon Harrop
2004-05-06 20:23 ` Alain.Frisch
2004-05-06 18:26 ` Olivier Grisel
2004-05-06 12:26 ` Julien Signoles
2004-05-06 16:35 ` brogoff
2004-05-02 17:18 ` David Brown
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=200405031941.46770.jdh30@cam.ac.uk \
--to=jdh30@cam.ac.uk \
--cc=caml-list@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