how to get the time in usec

J

JackyMove

Dear all,

I would like to get the time on how long to run a short segment of my
c program in usec under Windows platform using dev-c++. Is there any
method or function call to get it other than using clock()?

Thank you very much.

Regards,
Jacky
 
A

Alex Vinokur

JackyMove said:
Dear all,

I would like to get the time on how long to run a short segment of my
c program in usec under Windows platform using dev-c++. Is there any
method or function call to get it other than using clock()?

Thank you very much.

Regards,
Jacky

getrusage ()
http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?getrusage
http://www.opengroup.org/onlinepubs/007904975/functions/getrusage.html

-------------------------------------------------------------------------------------
http://www.hgmp.mrc.ac.uk/cgi-bin/man.cgi?section=3C&topic=getrusage
<QUOTE>
ru_utime The total amount of time spent executing in user
mode. Time is given in seconds and microseconds.

ru_stime The total amount of time spent executing in system
mode. Time is given in seconds and microseconds.
</QUOTE>
-------------------------------------------------------------------------------------

--
=====================================
Alex Vinokur
mailto:[email protected]
http://mathforum.org/library/view/10978.html
=====================================
 
T

Tim Prince

JackyMove said:
Dear all,

I would like to get the time on how long to run a short segment of my
c program in usec under Windows platform using dev-c++. Is there any
method or function call to get it other than using clock()?

Thank you very much.

Regards,
Jacky
clock() is the closest thing in standard C. I don't know what dev-c++ is,
but it's surely off topic. You could count CPU clock ticks. Look up rdtsc.
 
K

Keith Thompson

I would like to get the time on how long to run a short segment of my
c program in usec under Windows platform using dev-c++. Is there any
method or function call to get it other than using clock()?

Not in standard C, but I'm sure there are Windows-specific functions
that do what you want. Try a Windows-specific newsgroup.
 
R

Randy Howard

clock() is the closest thing in standard C. I don't know what dev-c++ is,
but it's surely off topic. You could count CPU clock ticks. Look up rdtsc.

Unfortunately, according to Intel there is no guarantee that rdtsc will
give you useful data on a SMP system, as the rdtsc result is not
synchronized between CPUs. If your process gets bumped to another CPU,
your results will be WAY off. This used to be good advice (if you didn't
mind not being portable off of some x86 CPUs), but with SMP systems
becoming increasingly common, it's horribly broken now. If you're using
a broken thread implementation (I.e. one which lets you pin a thread to a
physical CPU) then it might be useful for you, but only if the code gets
called from a single thread. For conventional processes, forget about it.
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top