From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 73B02BC6B for ; Wed, 7 Nov 2007 10:36:43 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAJ0VMUfAXQImh2dsb2JhbACOewEBAQgKKYEP X-IronPort-AV: E=Sophos;i="4.21,383,1188770400"; d="scan'208";a="19023135" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 07 Nov 2007 10:36:43 +0100 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id lA79aZK8029167 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 7 Nov 2007 10:36:42 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAEYWMUdA0DEbn2dsb2JhbACOewEBAQEHBAYRGIEP X-IronPort-AV: E=Sophos;i="4.21,383,1188770400"; d="scan'208";a="5536597" Received: from smail5.alcatel.fr ([64.208.49.27]) by mail3-smtp-sop.national.inria.fr with ESMTP; 07 Nov 2007 10:36:37 +0100 Received: from esmail03.netfr.alcatel.fr (esmail03.netfr.alcatel.fr [155.132.182.218]) by smail5.alcatel.fr (8.13.4/8.13.4/ICT) with ESMTP id lA79ZJaw015553 for ; Wed, 7 Nov 2007 10:35:21 +0100 Received: from [159.23.98.76] ([159.23.98.76]) by esmail03.netfr.alcatel.fr (Lotus Domino Release 5.0.13aHF163) with ESMTP id 2007110710363266:683 ; Wed, 7 Nov 2007 10:36:32 +0100 Message-ID: <473193E8.1070108@menta.net> Date: Wed, 07 Nov 2007 10:31:04 +0000 From: tmp123 User-Agent: Mozilla Thunderbird 0.9 (X11/20041105) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] log function without evaluate arguments References: <47309EEC.4080706@menta.net> <4a051d930711061938u25836a85ud28c610312e5896f@mail.gmail.com> In-Reply-To: <4a051d930711061938u25836a85ud28c610312e5896f@mail.gmail.com> X-MIMETrack: Itemize by SMTP Server on ESMAIL03/ES/ALCATEL(Release 5.0.13aHF163 | June 23, 2005) at 11/07/2007 10:36:32, Serialize by Router on ESMAIL03/ES/ALCATEL(Release 5.0.13aHF163 | June 23, 2005) at 11/07/2007 10:36:36, Serialize complete at 11/07/2007 10:36:36 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-Scanned-By: MIMEDefang 2.51 on 155.132.188.13 X-Miltered: at discorde with ID 47318723.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 syntax:01 printf:01 printf:01 val:01 val:01 stderr:01 gettimeofday:01 utime:01 gettimeofday:01 utime:01 16.:98 posibility:98 fmt:01 fmt:01 Hello, Thanks a lot to everybody for your help. I've been testing the different proposals. I must recognize I've not yet reviewed the proposed library, it is next step. The four methods tested are: lazy, fun, ifprint, and fun moving the "if" to the caller (see full listing and results at the end of the post). Two test has been done for each one: when parameter is an integer constant and when parameter is the result of a funcion call who mades an addition. The conclusion seems: defining that "lazy" method needs 1 unit of time, proposal using "fun" instead of lazy needs 0.8, and the version "ifprintf" needs 16. Proposal moving the "if" needs 0.7. Thus, if no error has been done, fun is the fastest option, lazy is near. Another point is the posibility of, using a camlp4 syntax extension, to introduce a few of sugar. Something like expand: from: log "some=%d\" 14; to: logint ( fun () -> Printf.printf "some=%d\n" 14); or to: if log_active.val then logint ( fun() -> Printf.printf "some=%d\n" 14) else (); Thanks again to everybody. Full listing and results: value log_active = ref False; value log1 exp = if log_active.val then Lazy.force exp else (); value log2 exp = if log_active.val then exp() else (); value log3 fmt = if log_active.val then Printf.printf fmt else Printf.ifprintf stderr fmt; value log4 exp = exp (); value suma a b = ( a+b; ); value some = ref 14; value test1 () = log1 (lazy (Printf.printf "%d" (suma some.val 3))); value test2 () = log2 ( fun () -> Printf.printf "%d" (suma some.val 3)); value test3 () = log3 "%d" (suma some.val 3); value test4 () = if log_active.val then log4 ( fun () -> Printf.printf "%d" (suma some.val 3)) else (); value testb1 () = log1 (lazy (Printf.printf "%d" 3)); value testb2 () = log2 ( fun () -> Printf.printf "%d" 3); value testb3 () = log3 "%d" 3; value testb4 () = if log_active.val then log4 ( fun () -> Printf.printf "%d" 3) else (); value loop f = ( let t=Unix.times() in Printf.printf "%f %f %f\n" (Unix.gettimeofday()) t.Unix.tms_utime t.Unix.tms_stime; for i = 0 to 1000 do for j = 0 to 1000000 do f (); done; done; let t=Unix.times() in Printf.printf "%f %f %f\n" (Unix.gettimeofday()) t.Unix.tms_utime t.Unix.tms_stime; ); value main () = ( Printf.printf "test1\n"; loop test1; Printf.printf "test2\n"; loop test2; Printf.printf "test3\n"; loop test3; Printf.printf "test4\n"; loop test4; Printf.printf "\n"; Printf.printf "testb1\n"; loop testb1; Printf.printf "testb2\n"; loop testb2; Printf.printf "testb3\n"; loop testb3; Printf.printf "testb4\n"; loop testb4; ); main(); Results: test1 1194426404.657406 0.015000 0.000000 1194426414.136406 9.453000 0.000000 test2 1194426414.137406 9.468000 0.000000 1194426422.147406 17.453000 0.000000 test3 1194426422.147406 17.453000 0.000000 1194426593.308406 188.515000 0.000000 test4 1194426593.308406 188.515000 0.000000 1194426599.964406 195.156000 0.000000 testb1 1194426599.964406 195.156000 0.000000 1194426609.408406 204.609000 0.000000 testb2 1194426609.408406 204.609000 0.000000 1194426617.378406 212.578000 0.000000 testb3 1194426617.378406 212.578000 0.000000 1194426790.412406 385.484000 0.000000 testb4 1194426790.412406 385.484000 0.000000 1194426797.060406 392.125000 0.000000 -------------