the time of the routine

  • Thread starter Romulo Carneiro
  • Start date
R

Romulo Carneiro

Hi people,
I wonder how I can calculate how much time any routine spend?
I 'd like to get date format minute and secund.
Thanks!
 
A

Arne Demmers

Romulo Carneiro said:
Hi people,
I wonder how I can calculate how much time any routine spend?
I 'd like to get date format minute and secund.
Thanks!

You should then take a look at time.h header file

Arne
 
R

Rod Pemberton

I wonder how I can calculate how much time any routine spend?
I 'd like to get date format minute and secund[sic].

Why do you want to do this in C (or C++)? The minimum resolution for C time
function will be much larger than the time spent in the C routine unless you
do something to slow down your code. Your best choice would be assembly.
For Intel cpu's, you'll need the 'rdtsc' instruction.


Rod Pemberton
 
K

Keith Thompson

Rod Pemberton said:
I wonder how I can calculate how much time any routine spend?
I 'd like to get date format minute and secund[sic].

Why do you want to do this in C (or C++)? The minimum resolution for C time
function will be much larger than the time spent in the C routine unless you
do something to slow down your code. Your best choice would be assembly.
For Intel cpu's, you'll need the 'rdtsc' instruction.

In C, the time() function measures real time (using the type time_t),
and the clock() function measures CPU time (using the type clock_t).
The standard doesn't define the resolution of either function. time()
typically has a resolution of 1 second; clock()'s resolution is
typically better. (The result returned by clock() is scaled by
CLOCKS_PER_SEC; this doesn't necessarily indicate the actual
resolution.)

Even if you need better resolution than time() and clock() can
provide, there's seldom any need to resort to assembly language.
There are plenty of system-specific timing routines (consult your
documentation or, if that fails, a system-specific newsgroup for
details). You could also use a profiler if your system provides one.
 
J

Jordan Abel

I wonder how I can calculate how much time any routine spend?
I 'd like to get date format minute and secund[sic].

Why do you want to do this in C (or C++)? The minimum resolution for C time
function will be much larger than the time spent in the C routine

Easy to say, given that among the absolutely nothing that the standard
says about time_t is included absolutely nothing about its resolution.

[Elsewhere, it also says nothing about the amount of time spent in any C
routine]
 
R

Rod Pemberton

Jordan Abel said:
I wonder how I can calculate how much time any routine spend?
I 'd like to get date format minute and secund[sic].

Why do you want to do this in C (or C++)? The minimum resolution for C time
function will be much larger than the time spent in the C routine

Easy to say, given that among the absolutely nothing that the standard
says about time_t is included absolutely nothing about its resolution.

[Elsewhere, it also says nothing about the amount of time spent in any C
routine]

Exactly, _nothing_ is guaranteed for time_t or clock_t. It could be large.
It could be small. But, when one is approaching 4Ghz (4 with 9 zeros) for
desktop CPU's, and faster even for mini-frames or main-frames, it's very
likely it won't be small enough. In which case, he'll need a CPU
instruction or a high-speed hardware clock. If he is using a PC, Intel's
rdtsc, Read Time-Stamp Counter Instruction, is 64-bits in size and
_guaranteed_ to increment by one for every CPU clock. The same or similar
would be true of a high-speed hardware clock. Calling a system function to
do the same thing that one or a few assembly instructions can do with much
less overhead doesn't make any sense in this situation, at least to me. I'm
not about to ignore reality, mathematics, or history, just because it isn't
in _the_ specification somewhere.


Rod Pemberton
 
K

Keith Thompson

Jordan Abel said:
I wonder how I can calculate how much time any routine spend?
I 'd like to get date format minute and secund[sic].

Why do you want to do this in C (or C++)? The minimum resolution for C time
function will be much larger than the time spent in the C routine

Easy to say, given that among the absolutely nothing that the standard
says about time_t is included absolutely nothing about its resolution.

It's not *quite* absolutely nothing. time_t is guaranteed to be an
arithmetic type capable of representing times. Nothing is said about
*how* it represents times; it needn't even be a linear or monotonic
mapping. But it can't be, for example, a pointer or a structure.
[Elsewhere, it also says nothing about the amount of time spent in any C
routine]

Actually, it says nothing in the same section.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,489
Latest member
BrigidaD91

Latest Threads

Top