Browse thread
Benchmarking different dispatch types
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Nathaniel Gray <n8gray@g...> |
| Subject: | Benchmarking different dispatch types |
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 -->