[SOLVED] An issue with 'tbb::tick_count' class

[SOLVED] An issue with 'tbb::tick_count' class

I detected an issue with 'tbb::tick_count' class. Please take a look at a test-case:

...
tbb::tick_count starttick;
tbb::tick_count endtick;

starttick = tbb::tick_count::now();
::Sleep( 5000 ); // 5000 ms = 5 seconds
endtick = tbb::tick_count::now();
_tprintf( _T("Task Delay: %ld secs\\n"), ( int )( endtick - starttick ).seconds() );
...

A delay is 5 seconds. However, '( endtick - starttick ).seconds()' returns 4 seconds. It is reproducible
with a test application compiled in Debug and Release configurations and TBBs v4 updates 3 and 1.

A generic description of the problem is as follows:

If a delay of N seconds is expected then '( endtick - starttick ).seconds()' always returns N-1 seconds.

My Development Environment:

OS : Windows XP 32-bit SP3
IDE: Visual Studio 2005 SP1
TBB: Version 4 Update 3
TBB: Version 4 Update 1

6 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

What do you get without casting to an integral type (which discards the entire fractional part)? And how would you be able to tell that it isn't Sleep() that's returnng a fraction too early? Have you compared with other timng API, or inspected the source code?

hello, what is a result in ms? ::Sleep() can return eariler than its arg. If result is 4999ms expect that result in seconds is '4'.
--Vladimir

Quoting Vladimir Polin (Intel)hello, what is a result in ms? ::Sleep() can return eariler than its arg. If result is 4999ms expect that result in seconds is '4'.
--Vladimir

I would expect an opposite due to amultitaskingin Windows OS.So,a real interval could be more than 5000ms.

Quoting Raf SchietekatWhat do you get without casting to an integral type (which discards the entire fractional part)? And how would you be able to tell that it isn't Sleep() that's returnng a fraction too early? Have you compared with other timng API, or inspected the source code?

Thanks for these tips andI'll take a look tomorrow.
Best regards,
Sergey

[SOLVED]. A 'seconds()' method returns aresult as a double-precisionfloating-pointvalue ( type 'double' ).

A modified test-case:

...
tbb::tick_count starttick;
tbb::tick_count endtick;

starttick = tbb::tick_count::now();
::Sleep( 2000 );
endtick = tbb::tick_count::now();
_tpintf( _T("Task Delay: %f secs\n"), ( endtick - starttick ).seconds() );
_tpintf( _T("Task Delay: %1.f secs\n"), ( endtick - starttick ).seconds() );
...

outputs correct results:

...
Task Delay: 1.988046 secs
Task Delay: 2 secs // Rounded by '_tprintf' to 1 digit
...

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen