Thread: GetTickCount()

  1. #1
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377

    GetTickCount()

    My GetTickCount() seems to always return the same value.
    Has this happened to you ?
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Yes, for something like:
    Code:
    #include <windows.h>
    #include <iostream>
    
    int main()
    {
    int i=200;
    
    while (i)
      {
      std::cout<<GetTickCount()<<"\n";
      --i;
      }
    
    std::cout<<std::endl;
    }
    Put a call to 'Sleep' in before the GetTickCount call and it will update. This is because GetTickCount is not very accurate.

    If you need a more precise timer then you can get millisecond precision with timeGetTime (if you set the period to 1ms with timeBeginPeriod). Windows also has high resolution timers but these may not be available with older machines - see QueryPerformanceCounter and QueryPerformanceFrequency. Search the boards, too, for these functions and 'timing'; I suspect you'll find previous discussions on the subject of timing that may be of interest.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    Yea GetTickCount will return the same value within the same millisecond. If you are using it to compare the speed of two functions, I would suggest putting the two functions in a for loop for about 10000 times or so, then comparing the running length of those two loops, it will be much more acurate.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    If you are timing something that has a smaller resolution than a millisecond, you can use a high resolution performance timer. See QueryPerformanceCounter().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Sleep and GetTickCount().
    By IamBMF in forum C Programming
    Replies: 13
    Last Post: 02-03-2008, 09:25 AM
  2. Something like GetTickCount()
    By rmullen3 in forum C++ Programming
    Replies: 3
    Last Post: 02-08-2003, 09:32 PM
  3. timeGetTime(), getSystemTime(), GetTickCount()
    By Shadow12345 in forum Windows Programming
    Replies: 1
    Last Post: 11-02-2002, 10:35 AM
  4. Time.h and GetTickCount()
    By SlimDady in forum C++ Programming
    Replies: 4
    Last Post: 04-12-2002, 09:50 AM