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 QAA29735; Tue, 20 Nov 2001 16:12:05 +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 QAA29478 for ; Tue, 20 Nov 2001 16:12:05 +0100 (MET) Received: from cantina.students.cs.unibo.it (cantina.students.cs.unibo.it [130.136.3.110]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id fAKFC3b09095 for ; Tue, 20 Nov 2001 16:12:03 +0100 (MET) Received: from lordsoth.takhisis.org ([192.168.1.116]) (authenticated (0 bits)) by cantina.students.cs.unibo.it (8.12.0.Beta19/8.12.0.Beta19/Debian 8.12.0.Beta19) with ESMTP id fAKFC0bE010040 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=192 verify=FAIL) for ; Tue, 20 Nov 2001 16:12:02 +0100 Received: from lordsoth.takhisis.org (localhost [127.0.0.1]) by lordsoth.takhisis.org (8.12.0/8.12.0/Debian -3) with ESMTP id fAKFBRdw032459 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=FAIL) for ; Tue, 20 Nov 2001 16:11:27 +0100 Received: (from zack@localhost) by lordsoth.takhisis.org (8.12.0/8.12.0/Debian -3) id fAKFBRt6032457 for caml-list@inria.fr; Tue, 20 Nov 2001 16:11:27 +0100 Date: Tue, 20 Nov 2001 16:11:27 +0100 From: Stefano Zacchiroli To: Inria Ocaml Mailing List Subject: [Caml-list] Benchmark: ref update vs argument passing Message-ID: <20011120161127.A32409@cs.unibo.it> Mail-Followup-To: Inria Ocaml Mailing List Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="UlVJffcvxoiEqYs2" Content-Disposition: inline User-Agent: Mutt/1.3.23i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline I'm modelling a small simulator, the simulator is implemented with a state machine that handle the event queue and with a scheduler that schedule new events. Another feature that the simulator have to handle is the accounting of various times. At the moment the times are kept away from the state of the state machine in a few global references that are updated when needed, because I thought that ref update is faster than passing these time across functions. I've written a small test that benchmark performance of passing argument between funcions vs. keep them in global reference (code attached). Surprisingly passing argument is really faster than update them through references, look at this: $ time ./a.out 1000000000 ref 1000000001 real 0m24.382s user 0m12.000s sys 0m0.000s $ time ./a.out 1000000000 arg 1000000001 real 0m5.317s user 0m2.660s sys 0m0.000s Are these tests realistic or I am missing something? Cheers! -- Stefano "Zack" Zacchiroli ICQ# 33538863 Home Page: http://www.cs.unibo.it/~zacchiro Undergraduate student of Computer Science @ University of Bologna, Italy - Information wants to be Open - --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename="ref_vs_passing.ml" (* check wether reference update is slower of faster than passing parameter between functions *) let rif = ref 0 in let endtime = int_of_string Sys.argv.(1) in let mode = Sys.argv.(2) in let rec use_refs time = rif := !rif + 1; if time>0 then use_refs (time-1) in let rec use_arg time arg = if time>=0 then use_arg (time-1) (arg+1) else arg in let main_ref () = use_refs endtime in let main_arg () = use_arg endtime 0 in let main () = match mode with | "ref" -> main_ref (); !rif | "arg" -> main_arg () | _ -> ~-1 in print_int (main ()); print_newline() --UlVJffcvxoiEqYs2-- ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr