LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-14-2007, 05:06 AM   #1
totaljj
LQ Newbie
 
Registered: Nov 2006
Posts: 6

Rep: Reputation: 0
using sleep() and time() commands together in c++


clock_t start, finish;
start=clock();
sleep(3);
finish=clock();

duration=(double(finish-start))/CLOCKS_PER_SEC;



above doesn't seem to add sleep time which is 3 seconds.
 
Old 02-14-2007, 07:12 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
clock() returns not the elapsed time (wall clock time), but the processor time; that is, the amount of time that the process has spent actually performing computation of some sort. Waiting on I/O doesn't count. Sleeping (more precisely, sleep()ing) doesn't count either.

That's why you probably got a duration of 0 seconds.

If you want a simple measure of elapsed time, see:

Code:
man 2 time
If you want something almost as simple but more precise, see:

Code:
man 2 gettimeofday
Hope this helps.

Last edited by wjevans_7d1@yahoo.co; 02-14-2007 at 07:13 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can ssh execute multiple commands at the same time? Singist Linux - Networking 2 04-04-2006 09:14 AM
Searching for Server (BOOTP/DHCP) <sleep> <sleep> .. .. Eileen Linux - Networking 12 10-21-2005 01:14 AM
Commands executed at boot time Johnburrell Linux From Scratch 3 09-18-2005 01:56 PM
Time commands from command line ToothlessRebel Linux - Newbie 1 03-09-2005 10:52 AM
how to let system to sleep at certain time? taoweijia Fedora 3 07-08-2004 04:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration