Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9160165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:40:21+00:00 2026-06-17T13:40:21+00:00

I am working towards achieving +/- ms timing precision. I want the time between

  • 0

I am working towards achieving +/- ms timing precision. I want the time between threads to be 10ms, but when I measure the time I get something closer to 15ms.

I am trying to understand if the problem is due to the way I am measuring time or if I am measuring the time accurately and there is some delay introduced by CreateTimerQueueTimer

My code looks like

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <chrono>
#include <ctime>
using namespace std;
int current;
long long* toFill;
void talk()
    {
    chrono::time_point<chrono::system_clock> tp = \
        chrono::system_clock::now();
    toFill[current++]=chrono::duration_cast<chrono::milliseconds>(tp.time_since_epoch()).count() ;
    }

int _tmain(int argc, _TCHAR* argv[])
    {
    HANDLE hTimer;
    current = 0;
    toFill = new long long[1000];
    CreateTimerQueueTimer(&hTimer,NULL, 
        (WAITORTIMERCALLBACK)talk,NULL,
        0,10,0);
    _sleep(3000);
    DeleteTimerQueueTimer(NULL,hTimer,NULL);
    for (int i = 1;i<current;i++)
        {
        cout << i << " : " << toFill[i]-toFill[i-1]<< endl;
        }
    return 0;
    }

Output looks like

...
161 : 16 <-- Should be 10
162 : 15
163 : 16
164 : 16
...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:40:22+00:00Added an answer on June 17, 2026 at 1:40 pm

    The accuracy of timers and the real time clock in Windows is limited by the clock tick interrupt rate. Which by default tocks 64 times per second, 1/64 sec = 15.625 msec. Just like you saw.

    Increasing that rate is actually possible, call timeBeginPeriod(10) at the start of your program to get 10 msec accuracy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working towards a solution for some time and could use a little
I am working towards getting rid of all link warnings, but I am getting
I'm working on a web application and want to create something like an invoice
I am trying to get django cms working with pinax but for some reason
I am a newbie working towards developing an IE extension that would appear as
This is a homework I am working towards to familiar myself with TDD and
Working with H2 I get this error when I try to write a row
Working with MS Access for the first time and coming across a few problems
So, I am a fairly new programmer working towards an undergraduate Comp Sci degree
I have couple years c programming experience. Now I decided to working towards Linux

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.