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

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

Sergey Kostrov的头像

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 帖子 / 0 new
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项
Raf Schietekat的头像

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?

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

Sergey Kostrov的头像
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.

Sergey Kostrov的头像
Quoting Raf Schietekat 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?

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

Sergey Kostrov的头像

[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
...

登陆并发表评论。