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 KAA05584; Wed, 5 May 2004 10:32:28 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA15611 for ; Wed, 5 May 2004 10:32:27 +0200 (MET DST) Received: from newext.lri.fr (ext.lri.fr [129.175.15.4]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i458WQSH004933 for ; Wed, 5 May 2004 10:32:26 +0200 Received: from serveur-mail.lri.fr (serveur-mail [129.175.8.90]) by newext.lri.fr (8.12.10/jtpda-5.4) with ESMTP id i458FWBG001773 ; Wed, 5 May 2004 10:15:32 +0200 (MEST) Received: from pc8-119.lri.fr (pc8-119 [129.175.8.119]) by serveur-mail.lri.fr (8.11.6p2/jtpda-5.3.2) with ESMTP id i458FWq20404 ; Wed, 5 May 2004 10:15:32 +0200 (MEST) Received: from localhost ([127.0.0.1]) by pc8-119.lri.fr with esmtp (Exim 3.36 #1 (Debian)) id 1BLHYy-000170-00; Wed, 05 May 2004 10:15:32 +0200 Date: Wed, 5 May 2004 10:15:32 +0200 (MEST) From: Julien Signoles To: Jon Harrop cc: caml-list@inria.fr Subject: Re: [Caml-list] Functors In-Reply-To: <200405031941.46770.jdh30@cam.ac.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-Miltered: at concorde with ID 4098A69A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; signoles:01 signoles:01 lri:01 caml-list:01 functors:01 functors:01 functorized:01 ocamldefun:01 inlining:01 closures:01 ocamldefun:01 slower:01 functor:01 ocamlopt:01 3.06:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > 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. It is what I mean too ;-). Sorry, my English is really perfectible. 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'm not sure because functors add closures which are difficult to inline. > 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. I test your example. Here are my results on a PIII 700 MHz, 64Mo, using ocamlopt.opt v3.06: ========== without using ocamldefun: Same compilation unit took 5.50491905212 Same compilation unit took 49.5608668327 55.000u 0.010s 0:55.07 99.8% 0+0k 0+0io 141pf+0w ========== As you said, this example is very slow when generated via a functor. ========== using ocamldefun: Same compilation unit took 5.50432610512 Same compilation unit took 5.50287103653 11.010u 0.000s 0:11.01 100.0% 0+0k 0+0io 140pf+0w ========== As you can see: no more loss of performance :-). Thank's a lot, I keep your example: it is really interesting for me. Cheers, Julien Signoles > 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