caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Execution time of class versus record
@ 2007-06-24 15:20 tmp123
  0 siblings, 0 replies; 5+ messages in thread
From: tmp123 @ 2007-06-24 15:20 UTC (permalink / raw)
  To: caml-list

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.






^ permalink raw reply	[flat|nested] 5+ messages in thread
[parent not found: <20070626065522.6175FBC77@yquem.inria.fr>]
* Execution time of class versus record
@ 2007-06-24 15:18 tmp123
  0 siblings, 0 replies; 5+ messages in thread
From: tmp123 @ 2007-06-24 15:18 UTC (permalink / raw)
  To: caml-list

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.






^ permalink raw reply	[flat|nested] 5+ messages in thread
* Execution time of class versus record
@ 2007-06-24 15:14 tmp123
  2007-06-26 13:35 ` Sam Steingold
  0 siblings, 1 reply; 5+ messages in thread
From: tmp123 @ 2007-06-24 15:14 UTC (permalink / raw)
  To: caml-list

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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-06-26 13:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-24 15:20 Execution time of class versus record tmp123
     [not found] <20070626065522.6175FBC77@yquem.inria.fr>
2007-06-26  7:36 ` David Allsopp
  -- strict thread matches above, loose matches on Subject: below --
2007-06-24 15:18 tmp123
2007-06-24 15:14 tmp123
2007-06-26 13:35 ` Sam Steingold

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