ChessUSA.com TalkChess.com
Hosted by Your Move Chess & Games
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

microsecond-accurate timing on Windows
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions Flat
View previous topic :: View next topic  
Author Message
Martin Sedlak



Joined: 26 Nov 2010
Posts: 701

PostPost subject: Re: microsecond-accurate timing on Windows    Posted: Mon May 28, 2012 8:07 pm Reply to topic Reply with quote

diep wrote:

Are you sure about timeGetTime()?

It has 100% same behaviour like GetTickCount() here.
Look:
Code:

#include <windows.h>
#include <Mmsystem.h>
#include <stdio.h>

#define BITBOARD unsigned long long

int main(void) {
  unsigned long long nattempts = 0ULL;
  unsigned int x, i = 0, dummy;


  if( timeBeginPeriod(1) == TIMERR_NOERROR )
    printf("set timer\n");
  else
    printf("error setting timer\n");
 
  x = (unsigned int)timeGetTime();//GetTickCount();   
  while( i < 50 ) {
    unsigned int newx = (unsigned int)timeGetTime();//GetTickCount();
    nattempts++;
    if( newx != x ) {
      unsigned int delta = newx - x;
      printf(" delta = %u totalreads = %llu\n",
       delta,nattempts);
      x = newx;
      i++;
    }   
  }

  if( timeEndPeriod(1) == TIMERR_NOERROR ) printf("ended timer\n");

  return 0;
}



That looks strange indeed. I see you even removed Sleep.
May I ask what hardware and OS are you using?

What bothers me are the first two lines of your output

diep wrote:

delta = 1 totalreads = 6731
delta = 35 totalreads = 6732


It looks like the first line is ok, after that it seems that the system was flooded and couldn't handle that because after that it's 35 msec for one read. So a possible solution would be to try a higher number than 1, perhaps 5 might work. I have read that timeBeginPeriod affects task scheduler.

Output of your code on my machine:

set timer
delta = 15 totalreads = 552126
delta = 16 totalreads = 574114
delta = 1 totalreads = 621069
delta = 1 totalreads = 673059
delta = 1 totalreads = 724305
delta = 1 totalreads = 775589
delta = 1 totalreads = 827283
delta = 1 totalreads = 878988
delta = 1 totalreads = 930644
delta = 1 totalreads = 982389
delta = 1 totalreads = 1034043
delta = 1 totalreads = 1085748
delta = 1 totalreads = 1188198
delta = 1 totalreads = 1239628
delta = 1 totalreads = 1291261
delta = 1 totalreads = 1342950
delta = 1 totalreads = 1394656
delta = 1 totalreads = 1446298
delta = 1 totalreads = 1497668
delta = 1 totalreads = 1549352
delta = 1 totalreads = 1601062
delta = 1 totalreads = 1652708
delta = 1 totalreads = 1704386
delta = 1 totalreads = 1754979
delta = 1 totalreads = 1806627
delta = 1 totalreads = 1858327
delta = 1 totalreads = 1910033
delta = 1 totalreads = 1961680
delta = 1 totalreads = 2013385
delta = 1 totalreads = 2065071
delta = 1 totalreads = 2114332
delta = 1 totalreads = 2165828
delta = 1 totalreads = 2217913
delta = 1 totalreads = 2269112
delta = 1 totalreads = 2320699
delta = 1 totalreads = 2366978
delta = 1 totalreads = 2419002
delta = 1 totalreads = 2471064
delta = 1 totalreads = 2523128
delta = 1 totalreads = 2574522
delta = 1 totalreads = 2626588
delta = 1 totalreads = 2678655
delta = 1 totalreads = 2730723
delta = 1 totalreads = 2782369
delta = 1 totalreads = 2833792
delta = 1 totalreads = 2884875
delta = 1 totalreads = 2936605
delta = 1 totalreads = 2987862
delta = 1 totalreads = 3039198
delta = 1 totalreads = 3090884
ended timer

It means that it takes some time before timeBeginPeriod takes effect. Shouldn't be an issue though.
Back to top
View user's profile Send private message
Display posts from previous:   
Subject Author Date/Time
microsecond-accurate timing on Windows Martin Sedlak Mon May 28, 2012 10:20 am
      Re: microsecond-accurate timing on Windows Martin Sedlak Mon May 28, 2012 12:56 pm
      Re: microsecond-accurate timing on Windows Vincent Diepeveen Mon May 28, 2012 2:44 pm
            Re: microsecond-accurate timing on Windows Martin Sedlak Mon May 28, 2012 3:22 pm
                  Re: microsecond-accurate timing on Windows Vincent Diepeveen Mon May 28, 2012 3:30 pm
                        Re: microsecond-accurate timing on Windows Martin Sedlak Mon May 28, 2012 5:10 pm
                              Re: microsecond-accurate timing on Windows Vincent Diepeveen Mon May 28, 2012 7:05 pm
            Re: microsecond-accurate timing on Windows Martin Sedlak Mon May 28, 2012 3:36 pm
                  Re: microsecond-accurate timing on Windows Vincent Diepeveen Mon May 28, 2012 3:39 pm
                        Re: microsecond-accurate timing on Windows Martin Sedlak Mon May 28, 2012 5:20 pm
                              Re: microsecond-accurate timing on Windows Vincent Diepeveen Mon May 28, 2012 6:23 pm
                                    Re: microsecond-accurate timing on Windows Martin Sedlak Mon May 28, 2012 7:13 pm
                                          Re: microsecond-accurate timing on Windows Vincent Diepeveen Mon May 28, 2012 7:18 pm
                                                Re: microsecond-accurate timing on Windows Martin Sedlak Mon May 28, 2012 8:33 pm
                                                      Re: microsecond-accurate timing on Windows Aleks Peshkov Tue May 29, 2012 7:50 am
                                                            Re: microsecond-accurate timing on Windows Martin Sedlak Tue May 29, 2012 8:26 am
                                          Re: microsecond-accurate timing on Windows Vincent Diepeveen Mon May 28, 2012 7:37 pm
                                                Re: microsecond-accurate timing on Windows Martin Sedlak Mon May 28, 2012 8:07 pm
                                                      Re: microsecond-accurate timing on Windows Vincent Diepeveen Tue May 29, 2012 12:44 pm
                                                            Re: microsecond-accurate timing on Windows Martin Sedlak Tue May 29, 2012 1:15 pm
                                                                  Re: microsecond-accurate timing on Windows Vincent Diepeveen Tue May 29, 2012 3:07 pm
                                                                        Re: microsecond-accurate timing on Windows Martin Sedlak Tue May 29, 2012 4:38 pm
                                                      Re: microsecond-accurate timing on Windows Vincent Diepeveen Tue May 29, 2012 12:55 pm
                                                      Re: microsecond-accurate timing on Windows Vincent Diepeveen Tue May 29, 2012 1:11 pm
                                                            Re: microsecond-accurate timing on Windows Martin Sedlak Tue May 29, 2012 1:29 pm
                                                                  Re: microsecond-accurate timing on Windows Vincent Diepeveen Tue May 29, 2012 3:18 pm
                                                                        Re: microsecond-accurate timing on Windows Martin Sedlak Tue May 29, 2012 5:00 pm
                                                                              Re: microsecond-accurate timing on Windows Wylie Garvin Tue May 29, 2012 9:38 pm
                                                                                    Re: microsecond-accurate timing on Windows Vincent Diepeveen Tue May 29, 2012 9:48 pm
                                                                                          Re: microsecond-accurate timing on Windows Martin Sedlak Wed May 30, 2012 9:10 am
                                                                                          Re: microsecond-accurate timing on Windows Vincent Diepeveen Fri Jun 01, 2012 9:24 am
                                                                                          Re: microsecond-accurate timing on Windows Martin Sedlak Fri Jun 01, 2012 10:52 am
                                                                                          Re: microsecond-accurate timing on Windows Vincent Diepeveen Sat Jun 02, 2012 3:36 pm
                                                                                          Re: microsecond-accurate timing on Windows Martin Sedlak Sun Jun 03, 2012 7:45 am
                                                                                          Re: microsecond-accurate timing on Windows Vincent Diepeveen Mon Jun 04, 2012 11:25 am
                                                                                          Re: microsecond-accurate timing on Windows Vincent Diepeveen Mon Jun 04, 2012 11:39 am
                                                                                          Re: microsecond-accurate timing on Windows Martin Sedlak Mon Jun 04, 2012 12:31 pm
                                                                                          Re: microsecond-accurate timing on Windows Martin Sedlak Mon Jun 04, 2012 12:12 pm
                                                                                    Re: microsecond-accurate timing on Windows Martin Sedlak Wed May 30, 2012 9:13 am
                                                                                          Re: microsecond-accurate timing on Windows Vincent Diepeveen Fri Jun 01, 2012 9:29 am
                                                                        Re: microsecond-accurate timing on Windows Martin Sedlak Tue May 29, 2012 5:25 pm
                                                                              Re: microsecond-accurate timing on Windows Vincent Diepeveen Tue May 29, 2012 7:19 pm
                                                                                    Re: microsecond-accurate timing on Windows Martin Sedlak Wed May 30, 2012 11:41 am
                                                                                          Re: microsecond-accurate timing on Windows Thomas Petzke Wed May 30, 2012 2:57 pm
                                                                              Re: microsecond-accurate timing on Windows Vincent Diepeveen Tue May 29, 2012 7:27 pm
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions

 
Jump to:  
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 vote in polls in this forum




Powered by phpBB © 2001, 2005 phpBB Group
Enhanced with Moby Threads