From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 5C933BC0B for ; Thu, 18 Jan 2007 02:12:33 +0100 (CET) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.240]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0I1CWtZ021179 for ; Thu, 18 Jan 2007 02:12:33 +0100 Received: by an-out-0708.google.com with SMTP id d26so29739and for ; Wed, 17 Jan 2007 17:12:32 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=FAFxiv6YS8a12EBcym6xCezLabLyd1zF9XHmV6Zovd1VMiHRGRWelIC6OGns4KMsPr34ngDjG5Jgs5ndIhanllPxgZ6m09SGcd4WhSVRMn1Fw+RyRzUjmuZY0ZCXJRP+xRMfCww1sb8zxBBnRG7m9vCAvhUH0feouNzJ4VsF55k= Received: by 10.78.166.7 with SMTP id o7mr241194hue.1169082750980; Wed, 17 Jan 2007 17:12:30 -0800 (PST) Received: by 10.78.198.14 with HTTP; Wed, 17 Jan 2007 17:12:30 -0800 (PST) Message-ID: Date: Wed, 17 Jan 2007 17:12:30 -0800 From: "Nathaniel Gray" To: "Caml List" Subject: Benchmarking different dispatch types MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-j-chkmail-Score: MSGID : 45AEC980.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45AEC980.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 -inline:01 foc:01 foc:01 usr:01 usr:01 16%:98 12%:98 89%:98 19%:98 sourceforge:01 compile:01 closure:01 closure:01 output:02 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 -->