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=2.3 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST,NO_REAL_NAME 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 6ADFFBC69 for ; Sun, 24 Jun 2007 17:20:23 +0200 (CEST) Received: from resmaa06.ono.com (smtp.ono.com [62.42.230.12]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5OFKMvG010112 for ; Sun, 24 Jun 2007 17:20:23 +0200 Received: from [192.168.1.33] (83.32.64.129) by resmaa06.ono.com (7.3.118.8) (authenticated as tmp123@menta.net) id 000000000001EF0D for caml-list@yquem.inria.fr; Sun, 24 Jun 2007 17:20:16 +0200 Message-ID: <467E8BAF.9040905@menta.net> Date: Sun, 24 Jun 2007 17:20:15 +0200 From: tmp123@menta.net User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Execution time of class versus record Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-j-chkmail-Score: MSGID : 467E8BB7.000 on discorde : j-chkmail score : XX : 5/20 0 0.000 -> 2 X-Miltered: at discorde with ID 467E8BB7.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocamlopt:01 mutable:01 printf:01 printf:01 gettimeofday:01 gettimeofday:01 val:01 mutable:01 unix:01 unix:01 slower:01 int:01 let:03 let:03 compiled:04 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? The programs are: records1.ml ========= type ra = { mutable t : int } let main () = let a = { t = 0 } in for i = 0 to 100000 do a.t <- a.t + i done; Printf.printf "t = %d\n" a.t let _ = let t0 = Unix.gettimeofday () in main(); Printf.printf "elapsed = %f\n" (Unix.gettimeofday() -. t0) class1.ml ======= class ca = object val mutable t = 0 method add x = t <- t+x method get () = t end let main () = let a = new ca in for i = 0 to 100000 do a#add i done; Printf.printf "t = %d\n" (a#get()) let _ = let t0 = Unix.gettimeofday () in main(); Printf.printf "elapsed = %f\n" (Unix.gettimeofday() -. t0) Thanks a lot.