Re: tool to measure performance of written function
- From: Eric Sosman <eric.sosman@xxxxxxx>
- Date: Mon, 09 May 2005 15:46:05 -0400
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
.
- Follow-Ups:
- References:
- tool to measure performance of written function
- From: cranium . 2003
- Re: tool to measure performance of written function
- From: Chris Croughton
- Re: tool to measure performance of written function
- From: Eric Sosman
- Re: tool to measure performance of written function
- From: Chris Croughton
- tool to measure performance of written function
- Prev by Date: Re: Complicated macro...
- Next by Date: Re: gcc4
- Previous by thread: Re: tool to measure performance of written function
- Next by thread: Re: tool to measure performance of written function
- Index(es):
Relevant Pages
|