Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Programming & Scripting > Best way to measure milliseconds?
 Linux Programming & Scripting   C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 11-19-2007   #1 (permalink)
Linux Newbie
 
Join Date: Jun 2006
Posts: 150
Best way to measure milliseconds?

What is the best way to measure milliseconds in c++ in linux? I'm using Allegro for the game that I'm making, any ideas?
Alaric is offline  

Reply With Quote
Old 11-19-2007   #2 (permalink)
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 1,192
I don't know anything about Allegro, but does this do the trick for you?
Code:
man gettimeofday
(Call it twice, subtract.)
__________________
--
Bill

Old age and treachery will overcome youth and skill.
wje_lf is offline   Reply With Quote
Old 11-19-2007   #3 (permalink)
Linux Newbie
 
Join Date: Jun 2006
Posts: 150
hmm... now why was I thinking that that responded in seconds? Oh well, looks like it will work . Thanks!
Alaric is offline   Reply With Quote
Old 11-19-2007   #4 (permalink)
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 1,192
You might have been thinking of this:
Code:
man 2 time
which, being only 32 bits wide, has its uses.
__________________
--
Bill

Old age and treachery will overcome youth and skill.
wje_lf is offline   Reply With Quote
Old 11-19-2007   #5 (permalink)
Linux Newbie
 
Join Date: Jun 2006
Posts: 150
...wait, this only returns the time in microseconds and seconds, which would be fine if the timer didn't overflow every quarter of a second or whatever... Is there a way to get timeval->tv_usec in something larger? I'm trying to write a simple game, and I need to make sure that the player can only fire his gun every half a second... Here's my function so far.

Code:
timeval now;
gettimeofday(&now);
if(now.tv_usec-this->LastShot<PLAYERSHOTTIME)
{
	return NULL;
}
this->LastShot=now.tv_usec;
But right now, whenever the user fires right before the timer turns over, they can never fire again... Any other suggestions?

p.s. How do I get those man pages? They've all given me page not found errors.
Alaric is offline   Reply With Quote
Old 11-20-2007   #6 (permalink)
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 1,192
Let's answer the more important (by far) question first:
Quote:
How do I get those man pages? They've all given me page not found errors.
Hmmmm. Man pages missing from your computer? Google this:
Code:
Linux man gettimeofday
From the google search results, choose the man page layout that pleases you most.

When you've read the man page, you'll see that you're interested in not just the tv_usec field, but also the tv_sec field. Both of them together specify the time of day; it's customary for the tv_usec field not to exceed 999999.

Questions after reading the man page? Come back. :)
__________________
--
Bill

Old age and treachery will overcome youth and skill.
wje_lf is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to measure response time using TCP events rahoolg Linux Networking 2 11-15-2007 05:18 PM
Tool or script to measure bandwdith koolkicks311 Redhat / Fedora Linux Help 1 04-28-2007 02:26 AM
measure tcp rate in SUSE KingMing SuSE Linux Help 0 12-02-2006 05:43 AM
How to measure the Internet connection speed ? libregeek Linux Networking 0 03-04-2006 06:26 AM
Measure the accept queueing time appforce The Linux Kernel 0 01-27-2006 07:42 PM

Free Magazines
Free Network Mapping Tool for Microsoft® Office Visio® Professional 2007 Users
Don't map your network by hand – let LANsurveyor Express for Microsoft Visio Professional 2007 automatically create network diagrams for you.
subscribe
Free eBook:"Vulnerability Management for Dummies"
Get all the Facts and See How to Implement a Successful Vulnerability Management Program.
subscribe
Google vs The World: The Battle of the Message Security Vendors
With such a powerful name behind it, Google Message Security stands out in a sea of products that do exactly the same thing - or so they say.
subscribe

Safe, Secure Backup


All times are GMT. The time now is 03:16 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2