Re: tool to measure performance of written function





Chris Croughton wrote:
> On Wed, 04 May 2005 14:13:20 -0400, Eric Sosman
> <eric.sosman@xxxxxxx> wrote:
>
>
>>
>>Chris Croughton wrote:
>>
>>> clock_t start, end;
>>> time_t tstart, tend;
>>> double t;
>>> [...]
>>> t = (end - start) / (float)CLOCKS_PER_SEC;
>>
>> (Drifting slightly): Why `float' and not `double'?
>
>
> Since I had double t; no real reason (except that it saves a character
> typing <g>).
>
>
>> In fact, there's even a faint possibility that
>>CLOCKS_PER_SEC could be `long double', so the cast to
>>mere `double' could lose precision. I'd suggest
>>writing
>>
>> t = (end - start) / (CLOCKS_PER_SEC + 0.0);
>
>
> Given the precision of CLOCKS_PER_SEC on most machines, I don't see the
> point. You'd be into sub-microsecond accuracy before you ran off the
> end of a float, and sub-nanosecond with a double (that's with the lowest
> precision for float and double allowed by the standard).

*Practical* arguments? *Real-world* reasons?! Hast
thou forgotten that thou'rt on comp.lang.c, where we worry
about things like padding bits in `short', eleven-bit `char',
and NULLs that aren't all-bits-zero? Pfui! Avaunt ye, thou
scalawag; thou'rt unworthy to be called Pedant! ;-)

> [...]
> Indeed. I think I'll deal with that warning if it ever arises (many
> programmers think that putting in casts to avoid warnings is bad anyway,
> putting them in to avoid a possible warning which is unlikely to happen
> is really going to annoy them)...

I once encountered a compiler that warned about
"possible loss of precision" for `float f = 0.0;', and
actually had to turn the change-approval crank to "fix"
it with `float f = 0.0f;' ...

--
Eric.Sosman@xxxxxxx

.



Relevant Pages

  • Re: tool to measure performance of written function
    ... > Chris Croughton wrote: ... no real reason (except that it saves a character ... so I'll take it out" -- making the cast explicit indicates to ... I think I'll deal with that warning if it ever arises (many ...
    (comp.lang.c)
  • Re: Question
    ... Warning test.c: 3 Assignment of int to unsigned short. ... Possible loss of precision ...
    (comp.lang.c)
  • Re: Question
    ... Warning test.c: 3 Assignment of int to unsigned short. ... Possible loss of precision ...
    (comp.lang.c)
  • Re: fortran help please!!!!
    ... DRIVER 3 NOV 80 ... WGS-72 PHYSICAL AND GEOPOTENTIAL CONSTANTS ... DOUBLE PRECISION EPOCH,DS50 ... There's nothing wrong w/ the Hollerith statements, it's simply a warning of an obsolescent/deleted feature but it will still function so the warnings can be ignored. ...
    (comp.lang.fortran)
  • Re: Errors in formula calculation
    ... >If I attempt to use precision as displayed a warning comes up that data will ... Yet it is inaccuracy of the calculation I am ...
    (microsoft.public.excel)