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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:44:18+00:00 2026-06-14T16:44:18+00:00

The boost chrono library vs1.51 on my macbook pro returns negative times when I

  • 0

The boost chrono library vs1.51 on my macbook pro returns negative times when I substract endTime – startTime. If you print the timepoints you see that the end time is earlier than the startTime. How can this happen?

typedef boost::chrono::steady_clock clock_t;
clock_t clock;

// Start time measurement
boost::chrono::time_point<clock_t>  startTime = clock.now();
short test_times = 7;

// Spend some time...
for ( int i=0; i<test_times; ++i )
{
   xnodeptr spResultDoc=parser.parse(inputSrc);

  xstring sXmlResult = spResultDoc->str();
  const char16_t* szDbg = sXmlResult.c_str();

  BOOST_CHECK(spResultDoc->getNodeType()==xnode::DOCUMENT_NODE && sXmlResult == sXml);
}

// Stop time measurement
boost::chrono::time_point<clock_t> endTime = clock.now();
clock_t::duration elapsed( endTime - startTime);

std::cout << std::endl;
std::cout << "Now time: " << clock.now() << std::endl;
std::cout << "Start time: " << startTime << std::endl;
std::cout << "End time: " << endTime << std::endl;

std::cout << std::endl << "Total Parse time: " << elapsed << std::endl;
std::cout << "Avarage Parse time per iteration: " <<  (boost::chrono::duration_cast<boost::chrono::milliseconds>(elapsed) / test_times) << std::endl;

I tried different clocks but no difference.

Any help would be appreciated!

EDIT: Forgot to add the output:

Now time: 1 nanosecond since boot

Start time: 140734799802912 nanoseconds since boot

End time: 140734799802480 nanoseconds since boot

Total Parse time: -432 nanoseconds
Avarage Parse time per iteration: 0 milliseconds

  • 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-14T16:44:20+00:00Added an answer on June 14, 2026 at 4:44 pm

    Hyperthreading or just scheduling interference, the Boost implementation punts monotonic support to the OS:

    POSIX: clock_gettime (CLOCK_MONOTONIC) although it still may fail due to kernel errors handling hyper-threading when calibrating the system.

    WIN32: QueryPerformanceCounter() which on anything but Nehalem architecture or newer is not going to be monotonic across cores and threads.

    OSX: mach_absolute_time(), i.e. the steady & high resolution clocks are the same. The source code shows that it uses RDTSC thus strict dependency upon hardware stability: i.e. no guarantees.

    Disabling hyperthreading is a recommended way to go, but say on Windows you are really limited. Aside of dropping timer resolution the only available method is direct access to the underlying hardware timers whilst ensuring thread affinity.

    It looks like a good time to submit a bug to Boost, I would recommend:

    Win32: Use GetTick64Count(), as discussed here.

    OSX: Use clock_get_time (SYSTEM_CLOCK) according to this question.

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

Sidebar

Related Questions

To use some recompiled libraries (f.ex. boost chrono) i need to specify the library
Are boost ptime instances always UTC? I can't see any time zone info on
C++0x thread library or Boost.thread define a non-member variadic template function that locks all
Boost library is full of examples and tests and I would like to build
Does boost chrono provides time stamp with nanoseconds resolution?? If yes how to get
Boost property tree seems like an excellent library to use for parsing config files.
In my C++ application I have a static library (libCOMMON.a) that links to boost
Boost Spirit library permits to Track the Input Position While Parsing . This mechanism
How interoperable are boost::date_time and std::chrono? For example, is there a way to convert
Boost::function is throwing me exceptions one out of ten times when I try to

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.