caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nathaniel Gray" <n8gray@gmail.com>
To: "Caml List" <caml-list@inria.fr>
Subject: Benchmarking different dispatch types
Date: Wed, 17 Jan 2007 17:12:30 -0800	[thread overview]
Message-ID: <aee06c9e0701171712k33761ed8r6dc30c46a9df6de7@mail.gmail.com> (raw)

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 -->


             reply	other threads:[~2007-01-18  1:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-18  1:12 Nathaniel Gray [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aee06c9e0701171712k33761ed8r6dc30c46a9df6de7@mail.gmail.com \
    --to=n8gray@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).