caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Benchmarking different dispatch types
@ 2007-01-18  1:12 Nathaniel Gray
  2007-01-18  2:17 ` [Caml-list] " Edgar Friendly
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Nathaniel Gray @ 2007-01-18  1:12 UTC (permalink / raw)
  To: Caml List

As somebody trying to understand the performance of OCaml, I've often
wondered about the performance of the different forms of function
dispatch.  How do method calls compare to function calls?  How about
closure calls?  So I tried using the Benchmark library[1] to do a
quick test:

========
(* Test method dispatch vs. function dispatch vs. closure dispatch
   Make sure to compile with -inline 0
 *)

let f x =
   x + 100
let call_f () = f 1

let o = object
   method f_o x = x + 100
end
let call_o () = o#f_o 1

let f_c () x = x + 100
let f_c' = f_c ()
let call_fc () = f_c' 1

let o_c = object
   method f_oc () x = x + 100
end
let f_oc' = o_c#f_oc ()
let call_foc () = f_oc' 1


open Benchmark

let _ =
   let results = latencyN 40000
      [("function", call_f, ());
       ("method", call_o, ());
       ("closure", call_fc, ());
       ("obj. closure", call_foc, ())]
   in
   tabulate results

========

Here's the output (on a PPC G4 1.25 GHz):

========
Latencies for 40000 iterations of function, method, closure, obj. closure:
  function:  0 WALL ( 0.00 usr + -0.00 sys =  0.00 CPU) @
305343511.45/s (n=40000)
            (warning: too few iterations for a reliable count)
    method:  0 WALL ( 0.00 usr + -0.00 sys =  0.00 CPU) @
27081922.82/s (n=40000)
            (warning: too few iterations for a reliable count)
   closure:  0 WALL ( 0.00 usr +  0.00 sys =  0.00 CPU) @
30280090.84/s (n=40000)
            (warning: too few iterations for a reliable count)
obj. closure:  0 WALL ( 0.00 usr +  0.00 sys =  0.00 CPU) @
26058631.92/s (n=40000)
            (warning: too few iterations for a reliable count)
                    Rate       method obj. closure      closure     function
      method  25974026/s           --          -5%         -16%         -90%
obj. closure  27210884/s           5%           --         -12%         -89%
     closure  31007752/s          19%          14%           --         -88%
    function 254777070/s         881%         836%         722%           --

Interesting, but are they meaningful?  The warnings from Benchmark are
troubling, but I didn't have any immediate ideas on how to get rid of
them.  Any suggestions?

Thanks,
-n8

[1] http://ocaml-benchmark.sourceforge.net

-- 
>>>-- Nathaniel Gray -- Caltech Computer Science ------>
>>>-- Mojave Project -- http://mojave.cs.caltech.edu -->


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-01-31 17:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-18  1:12 Benchmarking different dispatch types Nathaniel Gray
2007-01-18  2:17 ` [Caml-list] " Edgar Friendly
2007-01-18  3:03   ` Jonathan Roewen
2007-01-18 23:57     ` Nathaniel Gray
2007-01-18 15:52   ` Remi Vanicat
2007-01-18 22:33   ` Nathaniel Gray
2007-01-19  0:03     ` Robert Roessler
2007-01-31 17:03   ` Christophe TROESTLER
2007-01-18 16:56 ` William D. Neumann
2007-01-19  0:50 ` Jacques Garrigue
2007-01-19  8:30   ` Nathaniel Gray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).