caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: tmp123@menta.net
To: caml-list@inria.fr
Subject: Execution time of class versus record
Date: Sun, 24 Jun 2007 17:14:54 +0200	[thread overview]
Message-ID: <467E8A6E.9050700@menta.net> (raw)

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.





             reply	other threads:[~2007-06-24 15:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-24 15:14 tmp123 [this message]
2007-06-24 15:29 ` [Caml-list] " Jon Harrop
2007-06-24 15:48   ` Till Varoquaux
2007-06-24 16:06     ` Arnaud Spiwack
2007-06-24 18:18       ` skaller
2007-06-24 18:29       ` Gerd Stolpmann
2007-06-24 18:51         ` Arnaud Spiwack
2007-06-24 19:11           ` Chris King
2007-06-25  3:25           ` Jon Harrop
2007-06-25 11:16             ` Arnaud Spiwack
2007-06-25 12:07               ` Jon Harrop
2007-06-25 23:59                 ` Jonathan Bryant
2007-06-26  0:15                   ` Chris King
2007-06-26  6:53                     ` Loup Vaillant
2007-06-26  7:02                       ` Jon Harrop
2007-06-26 17:07                         ` Loup Vaillant
2007-06-28  1:13                 ` Christian Stork
2007-06-26 13:35 ` Sam Steingold
2007-06-26 16:29   ` [Caml-list] " Quôc Peyrot
2007-06-24 15:18 tmp123
2007-06-24 15:20 tmp123
     [not found] <20070626065522.6175FBC77@yquem.inria.fr>
2007-06-26  7:36 ` David Allsopp

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=467E8A6E.9050700@menta.net \
    --to=tmp123@menta.net \
    --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).