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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:31:48+00:00 2026-05-31T21:31:48+00:00

QueryPerformanceCounter() and Stopwatch.GetTimestamp() both return the tick count from one of the processors. I’d

  • 0

QueryPerformanceCounter() and Stopwatch.GetTimestamp() both return the tick count from one of the processors. I’d like to use the returned 64-bit integer value as a unique ID and I wonder if it’s possible that these functions return the same value when they’re called multiple times in a process.

My process would run for few hours at most at a time and these unique IDs are only used temporarily – they’re not saved in a database, for example. The above functions would be called several times but with other function calls in between.

The documentation states that it’s possible that a motherboard doesn’t support high-performance timers but all I’ve worked with had this support. My code would only run on 32-bit or 64-bit server hardware where I believe high-performance timers are always supported anyway (I’m not sure, though).

I could write a small test program to test it but that test would only be valid on my own computer so I’m looking for a more definitive answer, if one is available.

Edit: I know these functions are not designed to generate unique IDs but as long as they generate ever-increasing values, it’s fine. I’m asking this question not only for technical reason but out of curiosity as well.

  • 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-31T21:31:49+00:00Added an answer on May 31, 2026 at 9:31 pm

    Neither of the functions designed to return unique IDs. In fact it is likely 2 subsequent calls will return the same value.

    For unique identifiers consider using Guid.NewGuid or simply have counter with (interlocked) increment on each “give me ID” call.

    Proof of concept for “QueryPerformanceCounter” returns the same value:

    class Test
    {
        void Main()
        {
        long start1;    
        long start2;
        QueryPerfCounter.QueryPerformanceCounter(out start1);
        QueryPerfCounter.QueryPerformanceCounter(out start2);
    
        System.Console.WriteLine(start1);
        System.Console.WriteLine(start2);
        }
    
        [System.Runtime.InteropServices.DllImport("KERNEL32")]
        public static extern bool QueryPerformanceCounter(out long lpPerformanceCount);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it safe to assume that the count returned from QueryPerformanceCounter relates to the
Under Windows there are some handy functions like QueryPerformanceCounter from mmsystem.h to create a
I'm trying to run QueryPerformanceCounter() function from a particular process and get its return
LARGE_INTEGER lpPerformanceCount, lpFrequency; QueryPerformanceCounter(&lpPerformanceCount); QueryPerformanceFrequency(&lpFrequency); (Count.QuadPart is a long long showing a CPU count)
i'd like to switch bit with time shorter than 1 ms. I'd prefer do
Is there a performance impact from calling QueryPerformanceCounter over a less high-resolution timing method
I am trying to use valarray since it is much like MATLAB while operating
I would like to use the High Performance Event Timer (HPET) for an profiling
I'm making an application that needs some pretty tight timing, and the Stopwatch class
The following is a simple loop in C++. The timer is using QueryPerformanceCounter() and

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.