caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: Execution time of class versus record
       [not found] <20070626065522.6175FBC77@yquem.inria.fr>
@ 2007-06-26  7:36 ` David Allsopp
  2007-06-26  8:05   ` [Caml-list] " Nicolas Pouillard
  0 siblings, 1 reply; 3+ messages in thread
From: David Allsopp @ 2007-06-26  7:36 UTC (permalink / raw)
  To: caml-list

On Jun 26, 2007, at 08:53 AM, Loup Vaillant wrote:
> > For the same reason, there is a difference between:
> >
> >   type t = A of int * int
> >
> > and:
> >
> >   type t = A of (int * int)
>
> Err, I don't get it : I see exactly the same thing (written twice) here.
>
> Are you telling that :
> type t = A of int * int   <==>   type t = (A of int) * int
>
>?

The type declarations are different - the top-level reports a different type
in each case!

The brackets matter because they tell O'Caml how many *arguments* the
constructor A will take and so affect the internal representation.

With the first type declaration, A(1, 2) is a 2-argument constructor and the
value will be represented internally as a 2-field block with tag 0 with
field 0 containing 1 and field 1 containing 2. This means that this code
wouldn't work:

    let foo = (1, 2)
    in
      A foo

but with the second type declaration it would.

With the second type declaration, A (1, 2) is a 1-argument constructor and
will be represented internally as a 1-field block with tag 0 with field 0
"pointing" to another 2-field block containing the 1 and 2.

Section #18.3.4 of the manual explains the internal representation
difference (esp. with ref to #18.3.6 where it is compared to Polymorphic
Variants) but I was sure that there was an explicit reference in the manual
to the difference between the type declarations but I can't find it now :(

The confusion arises because the notation for arguments of a constructor and
tuple construction look the same - I believe the "revised" syntax for O'Caml
changes the way these are declared to make it clearer but I've never looked
at it...


David


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

* Re: [Caml-list] Re: Execution time of class versus record
  2007-06-26  7:36 ` Execution time of class versus record David Allsopp
@ 2007-06-26  8:05   ` Nicolas Pouillard
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Pouillard @ 2007-06-26  8:05 UTC (permalink / raw)
  To: David Allsopp; +Cc: caml-list

On 6/26/07, David Allsopp <dra-news@metastack.com> wrote:
> On Jun 26, 2007, at 08:53 AM, Loup Vaillant wrote:
> > > For the same reason, there is a difference between:
> > >
> > >   type t = A of int * int
> > >
> > > and:
> > >
> > >   type t = A of (int * int)
> >

[...]

> I believe the "revised" syntax for O'Caml
> changes the way these are declared to make it clearer but I've never looked
> at it...
>

Exactly:

type t = [ A of int and int ];

and

type t = [ A of (int * int) ];

-- 
Nicolas Pouillard


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

* Re: [Caml-list] Re: Execution time of class versus record
  2007-06-26 13:35 ` Sam Steingold
@ 2007-06-26 16:29   ` Quôc Peyrot
  0 siblings, 0 replies; 3+ messages in thread
From: Quôc Peyrot @ 2007-06-26 16:29 UTC (permalink / raw)
  To: caml-list


On Jun 26, 2007, at 3:35 PM, Sam Steingold wrote:

>> Please, knows someone what I'm doing wrong?
>>  let t0 = Unix.gettimeofday () in
>>  Printf.printf "elapsed = %f\n" (Unix.gettimeofday() -. t0)
>
> Unix.gettimeofday is "wall clock".
> Unix.times is "CPU time".
> use the latter to time your programs because the former depends on the
> machine load at the time of the test while the latter does not.

In my experience, you need both.

Thread locks, NFS latency, load and so on can indeed impact the wall  
clock
but it is ultimately what the customers are seeing. If you don't  
measure it,
you might be missing bugs or possible IO optimizations. Some code might
be looking perfectly fine in CPU time, but be catastrophic in real  
wall clock
due to various reasons.

But you also need the CPU Time to make sense of the wall clock time.
Once a slow part of the code is identified (using wall clock) and once
load or IO problems have been ruled out, it's good to use the CPU
time to measure any optimizations done.

What I meant is:
- most of the time, if the machine is not really overloaded CPU Time  
~= wall clock
   In this case, it's good to only look at the CPU Time
- If you see that overall, on all the measures in all parts of the  
program there is
   a huge difference between CPU and wall clock, then it is probably  
a general
   load problem
- But, you might see a huge difference only in certain part of the  
program,
   in such cases, it should be investigated.

If you only measure wall clock, or CPU Time, you might just miss some  
part
of the big picture.

My 2 cents

-- 
Best Regards,
Quôc




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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20070626065522.6175FBC77@yquem.inria.fr>
2007-06-26  7:36 ` Execution time of class versus record David Allsopp
2007-06-26  8:05   ` [Caml-list] " Nicolas Pouillard
2007-06-24 15:14 tmp123
2007-06-26 13:35 ` Sam Steingold
2007-06-26 16:29   ` [Caml-list] " Quôc Peyrot

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