Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 04-20-2004, 01:17 PM   #1
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?

Old 04-20-2004, 01:38 PM   #2
jim mcnamara
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
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32

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

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

		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



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:31 AM.

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