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 6957445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:00:11+00:00 2026-05-27T15:00:11+00:00

I am porting my application to windows from unix and I have run into

  • 0

I am porting my application to windows from unix and I have run into a wall. In my application I need to find time in microseconds (the whole application heavily depends on it due to it being a high precision application).

Previously I was using timespec structure, but windows contains no such thing. The command GetTickCount does not suffice because it returns time in milliseconds. I was also thinking of QueryPerformanceFrequency.

Would anyone happen to know something that is as identical to timespec as possible?

In the future I might even require nanoseconds too, which nothing I have searched in windows supports.

  • 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-05-27T15:00:12+00:00Added an answer on May 27, 2026 at 3:00 pm

    See, for example, How to realise long-term high-resolution timing on windows using C++? and C++ Timer function to provide time in nano seconds.

    I have done some testing with Cygwin under Windows XP: on my machine, the granularity of gettimeofday() is about 15 msecs (~1/64 secs). Which is quite coarse. And so is the granularity of:

    * clock_t clock(void) (divisor CLOCKS_PER_SEC)
    * clock_t times(struct tms *) (divisor sysconf(_SC_CLK_TCK))
    

    Both divisors are 1000 (POSIX may have 1000000 for first).

    Also, clock_getres(CLOCK_REALTIME,…) returns 15 msecs, so clock_gettime() is unlikely to help. And CLOCK_MONOTONIC and CLOCK_PROCESS_CPUTIME_ID don’t work.

    Other possibilites for Windows might be RDTSC; see the Wikipedia article. And HPET, which isn’t available with Windows XP.

    Also note in Linux, clock() is the process time, while in Windows it is the wall time.

    So some sample code, both for standard Unix, and for CYGWIN code running under Windows, which gives a granularity of about 50 microsecs (on my machine). The return value is in seconds, and gives the number of seconds elapsed since the function was first called. (I belatedly realized this was in an answer I gave over a year ago).

    #ifndef __CYGWIN32__
    double RealElapsedTime(void) { // returns 0 seconds first time called
       static struct timeval t0;
       struct timeval tv;
       gettimeofday(&tv, 0);
       if (!t0.tv_sec)
          t0 = tv;
       return tv.tv_sec - t0.tv_sec + (tv.tv_usec - t0.tv_usec) / 1000000.;
    }
    #else
    #include <windows.h>
    double RealElapsedTime(void) { // granularity about 50 microsecs on my machine
       static LARGE_INTEGER freq, start;
       LARGE_INTEGER count;
       if (!QueryPerformanceCounter(&count))
          FatalError("QueryPerformanceCounter");
       if (!freq.QuadPart) { // one time initialization
          if (!QueryPerformanceFrequency(&freq))
             FatalError("QueryPerformanceFrequency");
          start = count;
       }
       return (double)(count.QuadPart - start.QuadPart) / freq.QuadPart;
    }
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm porting my application into Linux (from Windows). I have such code: char buffer[32]
I just finished porting an application from Windows into Linux. I have to create
I am currently porting an application from iOS into Android and I have ran
I've run into an issue porting a codebase from linux (gcc) to windows (msvc).
i am porting my application from windows forms to WPF. I have found that
We have an application that we're porting to Mac OS from Windows. Once installed,
I'm porting an application written in C++ from Windows to Linux. I have a
I am porting my application to windows from Linux. I am fairly new to
I am porting a Windows application to OSX and need to get user's home,
Porting an application from C# (1.1 framework) to VB.NET (3.5 framework), and I have

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.