LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-20-2004, 01:17 PM   #1
deveraux83
Member
 
Registered: Jul 2003
Location: Malaysia
Distribution: Red Hat, Slackware 9.1
Posts: 76

Rep: Reputation: 15
timing in c++


Hi all,

Was just wondering the best method to keep track of time elapsed or just real time for that matter. I know that in glX code, you get use the function getMilliSeconds() to return time elapsed in milli seconds while in SDL you can use SDL_GetTicks() to do the same thing. However, is there a way of doing it in console mode?

I've tried reading some stuff on time/date in c++ but can't seem to figure it out (ie localtime/gmtime require a time argument). Any help/suggestions?

Thanks
 
Old 04-20-2004, 01:38 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
If I get what you want: gettimeofday() returns a very fine grained time.
It's in time.h
 
Old 04-20-2004, 05:34 PM   #3
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Time.h

Code:
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
	clock_t startTime=0;

	while(1)
	{
		startTime=clock();
		while((clock()-startTime)/CLOCKS_PER_SEC<1000); //Sleep one second
		printf("One second elapsed!");
	}    
}
Now I don't know if thats perfect, because its off the top of my head. But I do know you need to look into clock() from time.h

Enjoy!
 
  


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
Timing issues eagle683 Programming 4 06-01-2005 01:35 PM
kudzu Keeps Timing Out timswim78 Linux - Software 1 02-19-2005 01:11 PM
timing a function saajii Programming 1 10-25-2004 02:37 AM
mencoder timing delos Linux - Software 1 09-27-2004 02:24 PM
timing a process jonfa Linux - General 3 10-11-2001 04:33 PM

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

All times are GMT -5. The time now is 10:23 PM.

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