View unanswered posts | View active topics It is currently Mon Nov 24, 2014 12:48 am

Reply to topic  [ 3 posts ] 
 gettimeofday() inaccuracy 
Author Message

Joined: Fri Oct 03, 2008 4:18 am
Posts: 4
Hey folks,

I'm in search of a microsecond- or nanosecond-accurate timer for a project but the microsecond field returned from gettimeofday() is completely bogus. As a test I wrote a simple loop that calls gettimeofday() 100 times and prints the results each time before quitting.

Here's what it looks like in Windows (truncated for brevity, MinGW used):

1331965376; 300935
1331965376; 301935
1331965376; 302935
1331965376; 303935
1331965376; 304935
1331965376; 305935

This is what it looks like when ran on both a physical Wii and in the Dolphin emulator with any of the CPU options:

1331930967; 454
1331930967; 192
1331930967; 30
1331930967; 304
1331930967; 416
1331930967; 154

They are both in the order that they were executed. The Wii version doesn't just fail but it also bounces around with seemingly random numbers in the microsecond slot.

Is there anything that I can do either to fix gettimeofday() or replace it with another high-granularity timer?


Sat Mar 17, 2012 7:32 am

Joined: Fri Oct 03, 2008 4:18 am
Posts: 4
For the record, after much Google'ing around I finally found that if I use gettime() and diff_usec(start_time, current_time) I can get an elapsed time in microseconds.
There are various diff_ functions for different time measurements available.
All are found in <ogc/lwp_watchdog.h>

Thu Mar 22, 2012 12:54 am

Joined: Thu Dec 10, 2009 9:26 am
Posts: 36
It looks like __libogc_gettod_r() in timesupp.c should be using tick_to_microsecs() instead of tick_microsecs().

Sun Apr 01, 2012 1:52 pm
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
  Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.
Get devkitPro at Fast, secure and Free Open Source software downloads