[SOLVED] Which is correct time elapsed in running code
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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:
The elapsed time is not collected atomically with the execution of the program; as a result, in bizarre circumstances (if the time command gets stopped or swapped out in between when the program being timed exits and when time calculates how long it took to run), it could be much larger than the actual execution time.
When the running time of a command is very nearly zero, some values (e.g., the percentage of CPU used) may be reported as either zero (which is wrong) or a question mark.
Most information shown by time is derived from the wait3(2) system call. The numbers are only as good as those returned by wait3(2). On systems that do not have a wait3(2) call that returns status information, the times(2) system call is used instead. However, it provides much less information than wait3(2), so on those systems time reports the majority of the resources as zero.
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
/usr/bin/time wc /etc/hosts
Last edited by SaintDanBert; 07-03-2012 at 07:16 PM.
Distribution: Slackware 14, Debian 7.0.0 Wheezy, Windows 7, Windows 8
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?