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.2 required=5.0 tests=AWL,MAILTO_TO_SPAM_ADDR, 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 AE4E5BC69 for ; Sun, 24 Jun 2007 17:48:05 +0200 (CEST) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.229]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5OFm4RL017119 for ; Sun, 24 Jun 2007 17:48:05 +0200 Received: by nz-out-0506.google.com with SMTP id s1so986015nze for ; Sun, 24 Jun 2007 08:48:04 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=U/PfE3UfMlHM+E8s5b5LH9BqOJ8qpO9Y/+5HJLjtZOPhX0qOVennZpg2Xt9Odm1JHq5bMLhYviGcAna9YkBOzMzSERYVi0CWHrPZhpPEEOR56HYHgPxEMkI6j9T7uukSR/IseGGbtk6FqptAvMnzp5SL3wgJ0USUygwR+S+th8g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Gu+fonuQPEZ5x1NcjWAa/pVQyE/Bab1NMKLCGa/dB3FaIiHcbhkAa4ZEA0sSVyKkjVlbpUHKlTZNlTueVRPefvY1pqpLT8Iny29+Qq4V8YL84m5ccNfCIDa20FkmTOh++skU23Puric9Z9Amqah4+9giJugpY0i8W/+xjvIkZpI= Received: by 10.142.213.9 with SMTP id l9mr130557wfg.1182700084136; Sun, 24 Jun 2007 08:48:04 -0700 (PDT) Received: by 10.143.168.5 with HTTP; Sun, 24 Jun 2007 08:48:04 -0700 (PDT) Message-ID: <9d3ec8300706240848o6ac94a29q67f32d4774c88e0e@mail.gmail.com> Date: Sun, 24 Jun 2007 17:48:04 +0200 From: "Till Varoquaux" To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Execution time of class versus record In-Reply-To: <200706241629.50551.jon@ffconsultancy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <467E8A6E.9050700@menta.net> <200706241629.50551.jon@ffconsultancy.com> X-j-chkmail-Score: MSGID : 467E9234.001 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 467E9234.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 -dlambda:01 seq:01 pervasives:01 seq:01 pervasives:01 cheers:01 ocamlopt:01 ocaml:01 beginner's:01 bug:01 frog:98 beginners:01 wrote:01 wrote:01 Objects in OCaml are dictionary based, which means methods names must be looked up in a table in order to get there addresses. Record fields on the other hand are addressed directly. Take two files test.ml and test2.ml: test.ml: type b= { field:int } let a={field=1};; print_int a.field test2.ml let a=object method field=1 end;; print_int a#field and dump there intermediate representation (-dlambda) test.ml (setglobal Test! (let (a/61 [0: 1]) (seq (apply (field 27 (global Pervasives!)) (field 0 a/61)) (makeblock 0 a/61)))) test2.ml (setglobal Test2! (let (a/58 (let (class/72 (apply (field 15 (global CamlinternalOO!)) [0: #"field"]) obj_init/80 (let (field/61 (apply (field 6 (global CamlinternalOO!)) class/72 #"field")) (seq (apply (field 10 (global CamlinternalOO!)) class/72 (makeblock 0 field/61 0a 1)) (function env/74 (apply (field 23 (global CamlinternalOO!)) 0a class/72))))) (seq (apply (field 16 (global CamlinternalOO!)) class/72) (apply obj_init/80 0a)))) (seq (apply (field 27 (global Pervasives!)) (send a/58 9671866)) (makeblock 0 a/58)))) You can now understand where the performance issues comes from. Cheers, Till On 6/24/07, Jon Harrop wrote: > On Sunday 24 June 2007 16:14:54 tmp123@menta.net wrote: > > Hello, > > > > I've tried to implement two equivalent small programs, the one using > > class, the other one using records. The resulting execution times says > > that class are 7-8 times slower than record (compiled with ocamlopt in a > > Intel machine). > > > > Please, knows someone what I'm doing wrong? > > You aren't doing anything wrong. > > -- > Dr Jon D Harrop, Flying Frog Consultancy Ltd. > The OCaml Journal > http://www.ffconsultancy.com/products/ocaml_journal/?e > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- http://till-varoquaux.blogspot.com/