|
Boost : |
Subject: Re: [boost] [chrono] steady_clock efficiency
From: Kenneth Porter (shiva.blacklist_at_[hidden])
Date: 2011-11-29 20:25:47
"Vicente J. Botet Escriba" <vicente.botet_at_[hidden]> wrote in
news:4ED49A27.2030500_at_[hidden]:
> Glad to hear you are considering it. Have you any measures that let you
> think there is a serious overhead? How do you use the ::now() function
> to make your performance measures?
Thanks for the feedback. A typical use case:
const time_point startTime = steady_clock::now();
// stuff to measure here
const time_point endTime = steady_clock::now();
const duration elapsed = endTime - startTime;
Ideally the conversion from ticks to nanoseconds would be done by the
subtraction operator.
Another use case, waiting a precise amount of time:
void wait(const duration timeToWait)
{
const time_point endTime = steady_clock::now() + timeToWait;
while (steady_clock::now() < endTime)
;
}
Here, the conversion from nanoseconds to ticks would be done by the
addition operator, so that the time_point comparison would be in ticks.
I'd use this where I need to wait a small amount of time (much less than a
scheduler tick) for a hardware device to respond, before giving up my time
slice.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk