0
Q:
Hi
I want to measure the time required to execute a piece of code.
For example, I want to know the time required to execute a given
function. How do I do it within C++? I know I got to use a library
called ctime. But I dont know what functions to use. Please tell me.
A:
include time.h in your C++ file
clock_t start, finish;
start = clock();
// your code here
finish = clock();
( (finish - start)/CLOCKS_PER_SEC )
should give the time taken by your code
~Madhav
I reccomend you to use this class:
http://oldmill.uchicago.edu/~wilder/Code/timer/
It is pretty simple and easy to use. I have used it in a lot of my code
snippets, works very well. It is time resolution is also high.
simply don't devide by CLOCKS_PER_SEC
(finish - start) will give you the CPU clocks occured in between.
And I am not sure if sombody can get time detailed to less than the CPU
clock
~Madhav
Hi
I want to measure the time required to execute a piece of code.
For example, I want to know the time required to execute a given
function. How do I do it within C++? I know I got to use a library
called ctime. But I dont know what functions to use. Please tell me.
A:
include time.h in your C++ file
clock_t start, finish;
start = clock();
// your code here
finish = clock();
( (finish - start)/CLOCKS_PER_SEC )
should give the time taken by your code
~Madhav
I reccomend you to use this class:
http://oldmill.uchicago.edu/~wilder/Code/timer/
It is pretty simple and easy to use. I have used it in a lot of my code
snippets, works very well. It is time resolution is also high.
simply don't devide by CLOCKS_PER_SEC
(finish - start) will give you the CPU clocks occured in between.
And I am not sure if sombody can get time detailed to less than the CPU
clock
~Madhav
| 引用(0)
An incomplete list of C++ compilers
map with pair as key


2006/06/22
12:53
5599



