From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA29861; Mon, 3 May 2004 20:42:15 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA29838 for ; Mon, 3 May 2004 20:42:14 +0200 (MET DST) Received: from ptb-relay01.plus.net (ptb-relay01.plus.net [212.159.14.212]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i43IgDEV018519 for ; Mon, 3 May 2004 20:42:13 +0200 Received: from [80.229.56.224] (helo=chetara) by ptb-relay01.plus.net with esmtp (Exim) id 1BKiOJ-0002I5-9B for caml-list@inria.fr; Mon, 03 May 2004 18:42:11 +0000 From: Jon Harrop Organization: University of Cambridge To: caml-list@inria.fr Subject: Re: [Caml-list] Functors Date: Mon, 3 May 2004 19:41:46 +0100 User-Agent: KMail/1.5.4 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200405031941.46770.jdh30@cam.ac.uk> X-Miltered: at nez-perce with ID 40969285.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 functors:01 2004:99 signoles:01 ocamldefun:01 functors:01 inlined:01 functorized:01 ocamldefun:01 inlining:01 slower:01 functor:01 val:01 struct:01 functor:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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