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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:58:08+00:00 2026-05-16T04:58:08+00:00

LARGE_INTEGER lpPerformanceCount, lpFrequency; QueryPerformanceCounter(&lpPerformanceCount); QueryPerformanceFrequency(&lpFrequency); (Count.QuadPart is a long long showing a CPU count)

  • 0
LARGE_INTEGER lpPerformanceCount, lpFrequency;

QueryPerformanceCounter(&lpPerformanceCount);
QueryPerformanceFrequency(&lpFrequency);

(Count.QuadPart is a long long showing a CPU count)

(Freq.QuadPart is a long long showing frequency of Count for a second)

Attempting to print microseconds in real time.

stable output:

printf("%llu\n", ((long double)lpPerformanceCount.QuadPart/ lpFrequency.QuadPart) * 1000000);

erratic output: (result jumps incoherently front and back even if it’s at first glance sane)

printf("%llu\n", 1000000 * (lpPerformanceCount.QuadPart / lpFrequency.QuadPart) + (lpPerformanceCount.QuadPart % lpFrequency.QuadPart));

EDIT: printf needed a further (unsigned long long) conversion in its input, the original code had that done by a return value of a func.

  • 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-16T04:58:08+00:00Added an answer on May 16, 2026 at 4:58 am

    Are you sure %llu prints a reasonable double?

    lpPerformanceCount.QuadPart / lpFrequency.QuadPart gives you a time, rounded to full seconds.

    lpPerformanceCount.QuadPart % lpFrequency.QuadPart gives you a tick count (number ticks since last full second).

    Adding a count to a time gives you.. how to put that politely… crap.

    I alway use the double arithmetics, much less hassle. However, if you insist in non-FPU code, you could use:

    count.QuadPart*1000000 / (freq.QuadPart*1000000)
    

    which would overflow faster (though not a practical problem I’d assume). Fixing that up for integer arithmetics:

    count.QuadPart / freq.QuadPart 
    + (count.QuadPart % freq.QuadPart) * 1000000 / freq.QuadPart
    

    (I hope that’s right…)

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

Sidebar

Related Questions

Consider this code: LARGE_INTEGER l; size_t s; if (s < l.QuadPart) return 1; return
Based upon this question How to declarate LARGE_INTEGER in C# with answer of: [StructLayout(LayoutKind.Absolute,
typedef struct _FILE_BOTH_DIR_INFORMATION { ULONG NextEntryOffset; ULONG FileIndex; LARGE_INTEGER CreationTime; LARGE_INTEGER LastAccessTime; LARGE_INTEGER LastWriteTime;
the line if(arg2 & 1) in C++(arg2 is DWORD) is equal to if(arg2 &
I have two logically equivalent functions: long ipow1(int base, int exp) { // HISTORICAL
I am working on a CPU-heavy numerical computation app. Without going into many details,
Efficiency of the map::insert(iterator position, const value& k) can be dramatically improved by providing
How do I divide a large positive integer n into m parts uniformly randomly
The program requires an input of an arbitrary large unsigned integer which is expressed
I have an integer value that spans a range so large it is impractical

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.