Boost logo

Boost Users :

Subject: [Boost-users] Trouble with posix_time
From: Davies, John (john.davies_at_[hidden])
Date: 2013-06-04 12:29:19


I'm trying to time part of my program and coming up with something I can't explain. I don't expect great accuracy with the sample code here. But I'd like to understand what is happening.

static boost::posix_time::ptime MillisecondsFromNow(int milliseconds)
{
    return(boost::posix_time::ptime(boost::posix_time::second_clock::universal_time()) +
                                                    boost::posix_time::milliseconds(milliseconds));
}

Code segment:

    nanosecond_type const twenty_seconds(20 * 1000000000LL);
    cpu_timer timer;
    long count = 0;
    while(true)
    {
        boost::thread::sleep(MillisecondsFromNow(1000));

        cpu_times const elapsed_times(timer.elapsed());
        nanosecond_type const elapsed(elapsed_times.wall);

        if (elapsed >= twenty_seconds)
        {
            break;
        }
        count++;
    }

    std::cout << count << '\n';

So I'm running for 20 seconds and delaying each time for a second. So I would expect to get output of 19, maybe 20 or 18. Instead I'm getting around 38-40

I've tried .system and .user and get different values. But never something close to 20.

This is on Windows.

___________________________________

John Davies
Contractor
Home Respiratory Care
Philips Home Healthcare Solutions
1740 Golden Mile Highway
Monroeville, PA 15146

Email: john.davies_at_[hidden]
Fax: 724-387-4109

________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net