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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:41:41+00:00 2026-05-14T18:41:41+00:00

I am looking for ways to perform micro-benchmarks on multi-core processors. Context: At about

  • 0

I am looking for ways to perform micro-benchmarks on multi-core processors.

Context:

At about the same time desktop processors introduced out-of-order execution that made performance hard to predict, they, perhaps not coincidentally, also introduced special instructions to get very precise timings. Example of these instructions are rdtsc on x86 and rftb on PowerPC. These instructions gave timings that were more precise than could ever be allowed by a system call, allowed programmers to micro-benchmark their hearts out, for better or for worse.

On a yet more modern processor with several cores, some of which sleep some of the time, the counters are not synchronized between cores. We are told that rdtsc is no longer safe to use for benchmarking, but I must have been dozing off when we were explained the alternative solutions.

Question:

Some systems may save and restore the performance counter and provide an API call to read the proper sum. If you know what this call is for any operating system, please let us know in an answer.

Some systems may allow to turn off cores, leaving only one running. I know Mac OS X Leopard does when the right Preference Pane is installed from the Developers Tools. Do you think that this make rdtsc safe to use again?

More context:

Please assume I know what I am doing when trying to do a micro-benchmark. If you are of the opinion that if an optimization’s gains cannot be measured by timing the whole application, it’s not worth optimizing, I agree with you, but

  1. I cannot time the whole application until the alternative data structure is finished, which will take a long time. In fact, if the micro-benchmark were not promising, I could decide to give up on the implementation now;

  2. I need figures to provide in a publication whose deadline I have no control over.

  • 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-14T18:41:42+00:00Added an answer on May 14, 2026 at 6:41 pm

    On OSX (ARM, Intel and PowerPC), you want to use mach_absolute_time( ):

    #include <mach/mach_time.h>
    #include <stdint.h>    
    
    // Utility function for getting timings in nanoseconds.
    double machTimeUnitsToNanoseconds(uint64_t mtu) {
        static double mtusPerNanosecond = 0.0;
        if (0.0 == mtusPerNanosecond) {
            mach_timebase_info_data_t info;
            if (mach_timebase_info(&info)) {
                // Handle an error gracefully here, whatever that means to you.
                // If you do get an error, something is seriously wrong, so
                // I generally just report it and exit( ).
            }
            mtusPerNanosecond = (double)info.numer / info.denom;
        }
        return mtu * mtusPerNanosecond;
    }
    
    // In your code:
    uint64_t startTime = mach_absolute_time( );
    // Stuff that you want to time.
    uint64_t endTime = mach_absolute_time( );
    double elapsedNanoseconds = machTimeUnitsToNanoseconds(endTime - startTime);
    

    Note that there’s no need to limit to one core for this. The OS handles the fix-up required behind the scenes for mach_absolute_time( ) to give meaninful results in a multi-core (and multi-socket) environment.

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

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I was also considering to use some sort of encryption,… May 14, 2026 at 8:19 pm
  • Editorial Team
    Editorial Team added an answer Some remarks/questions: Do you really get only [PersistenceUnit: MyHibernatePgSql] Unable… May 14, 2026 at 8:19 pm
  • Editorial Team
    Editorial Team added an answer The WebBrowser control is essentially just an embedded version of… May 14, 2026 at 8:19 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.