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 SAA15121; Tue, 5 Nov 2002 18:09:04 +0100 (MET) 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 SAA14599 for ; Tue, 5 Nov 2002 18:09:03 +0100 (MET) Received: from grisu.bik-gmbh.de (grisu.bik-gmbh.de [217.110.154.194]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gA5H92510385 for ; Tue, 5 Nov 2002 18:09:02 +0100 (MET) Received: from bik-gmbh.de (prony.bik-gmbh.de [194.233.237.133]) by grisu.bik-gmbh.de (8.12.3/8.12.3) with ESMTP id gA5H8xU8056703; Tue, 5 Nov 2002 18:09:00 +0100 (CET) (envelope-from hars@bik-gmbh.de) Message-ID: <3DC7FB24.9030209@bik-gmbh.de> Date: Tue, 05 Nov 2002 18:08:52 +0100 From: Florian Hars User-Agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.1) Gecko/20020826 X-Accept-Language: de-de, en-us, en MIME-Version: 1.0 To: Magesh Kannan CC: caml-list@inria.fr Subject: Re: [Caml-list] Currying vs Speed References: Content-Type: multipart/mixed; boundary="------------050208080001020206080103" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk This is a multi-part message in MIME format. --------------050208080001020206080103 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Magesh Kannan wrote: > Does the invocation (my_func_part 10 20) run any faster than > (my_func_wrapper 5 10 20)? It is comparable if you compile to bytecode, and much worse if you compile to native code. In that case, you may loose more than a factor of ten: $ ./bench my_func: 16.4 sec my_func_wrapper: 20.2 sec my_func_part: 17.1 sec $ ocamlopt -inline 0 -o bench unix.cmxa bench.ml $ ./bench my_func: 0.6 sec my_func_wrapper: 0.8 sec my_func_part: 2.2 sec $ ocamlopt -inline 10 -o bench unix.cmxa bench.ml $ ./bench my_func: 0.2 sec my_func_wrapper: 0.2 sec my_func_part: 2.3 sec A full application of a function is optimized far better than a partial one. Especially in the -inline 10 case, the function call is completely optimized away for the two fully applied versions. Yours, Florian Hars. --------------050208080001020206080103 Content-Type: text/plain; name="bench.ml" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="bench.ml" let my_func arg1 arg2 arg3 = let res = arg1 + arg2 + arg3 in res let my_func_wrapper arg1 arg2 arg3 = my_func arg1 arg2 arg3 let my_func_part = my_func 5 let _ = let t0 = Unix.gettimeofday () in let five = 5 in let r = ref 0 in for i = 0 to 10000 do for j = 0 to 10000 do r := !r + my_func five i j done done; Printf.printf "my_func: %.1f sec\n" (Unix.gettimeofday () -. t0); let t0 = Unix.gettimeofday () in let five = 5 in let r = ref 0 in for i = 0 to 10000 do for j = 0 to 10000 do r := !r + my_func_wrapper five i j done done; Printf.printf "my_func_wrapper: %.1f sec\n" (Unix.gettimeofday () -. t0); let t0 = Unix.gettimeofday () in let r = ref 0 in for i = 0 to 10000 do for j = 0 to 10000 do r := !r + my_func_part i j done done; Printf.printf "my_func_part: %.1f sec\n" (Unix.gettimeofday () -. t0) --------------050208080001020206080103-- ------------------- 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