Which is correct time elapsed in running code
Hello,
i used two methods to compute time elapsed in one of my program First is from ctime library, Code:
clock_t start=clock(); Code:
me@maths131:~$ gcc -Wall -fopenmp canon.cpp -lstdc++ I am confused which is right? And its important. PS: if "time" is right, then suggest some commands to use that time in cpp code in runtime. And i was coding OpenMP (Parallel Processing) in CPU with two cores. |
In your first fragment, it appears that START and STOP are reversed
... or do my old eyes play tricks on me? The following might speak to some of your concerns, but I don't know for certain. I also have not direct knowledge of how the results from various system calls and commands are affected by multi-core processors. The man page for the 'time' command offers the following: Code:
Code:
Users of the bash shell need to use an explicit path in order to run the external time command and not the shell builtin variant. On system where time is installed in /usr/bin, the first example would become |
Try also
Code:
\time ./a.out 1000 400 |
Thank you for your replies, and sorry, yes i mistyped that.
Somehow i know that time command is giving me correct result. I compared it with stopwatch and found approx equal. Actually, i have to run loop for 500 times and calculate time elapsed for each loop. So i need "clock_t" to trigger time. But when i checked the correctness of "clock_t" i got confused. Why is it wrong? Because program is a parallel algorithm using two cores simultaneously? Is the time shown by "clock_t" 10.29 is exactly two times (because of 2 cores) of its actual value? Or any other reasons? Please |
Quote:
|
Hmm.. That's what i thought too. Well i think i am clear.
BTW, i'll be using Code:
#include <sys/time.h> Thank you all for your helps. |
If you're interested, you might try rebooting with maxcpus=1. That way all the code will ahve to run on the one processor, and should make the numbers more "sensible".
|
Thank you syg00, But i am working under a Project on Parallel Processing. So i must have to use more than one cores and threads.
|
Here's the link of an example of gettimeofday() :
http://www.ccplusplus.com/2011/11/ge...y-example.html As gnu-time uses gettimeofday() in order to get microseconds precision. |
All times are GMT -5. The time now is 12:29 AM. |