[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] Sporadic error in 'timer_test'
From: |
Greg Chicares |
Subject: |
[lmi] Sporadic error in 'timer_test' |
Date: |
Wed, 11 Nov 2015 16:08:51 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0 |
A few weeks ago I saw this failure:
**** test failed: '0.975153' < '0.032'
[file /lmi/src/lmi/timer_test.cpp, line 126]
and something similar occurred just the other day:
**** test failed: '0.974785' < '0.032'
[file /lmi/src/lmi/timer_test.cpp, line 126]
so I'm wondering what could be wrong with TimerTest::TestResolution().
I made this local change, to get more information...
Index: timer_test.cpp
===================================================================
--- timer_test.cpp (revision 6402)
+++ timer_test.cpp (working copy)
@@ -124,6 +124,15 @@
double relative_error = std::fabs(observed - interval) / interval;
BOOST_TEST_RELATION(relative_error,<,2.0*clock_resolution);
+
+ std::cout
+ << CLOCKS_PER_SEC << " CLOCKS_PER_SEC\n"
+ << clock_resolution << " clock_resolution\n"
+ << observed << " observed\n"
+ << interval << " interval\n"
+ << relative_error << " relative_error\n"
+ << std::endl
+ ;
}
void TimerTest::TestExceptions()
...and changing the code made the problem disappear. Now I see, e.g.:
1000 CLOCKS_PER_SEC
0.015 clock_resolution
1.00005 observed
1 interval
4.94609e-05 relative_error
AIUI, the msw-xp clock ticks 64 times per second, so 'clock_resolution'
looks correct, and so do the failing tests cited above--they report
BOOST_TEST_RELATION(relative_error,<,2.0*clock_resolution);
^^^^^^^^^^^^^^^^^^^^
two times 'clock_resolution', which should be between .030 and .032 .
I run it a hundred times:
for a in {1..100}; do ./timer_test --accept ; done 2>&1 |less
and the test never fails.
As a last resort, I looked at the code, but it uses the C RTL, which
I don't remember well. Now I'm staring at this and wondering how it
can work:
std::clock_t first = std::clock();
std::clock_t last;
double clock_resolution;
for(;;)
{
last = std::clock();
clock_resolution = double(last - first) / CLOCKS_PER_SEC;
if(0.0 != clock_resolution)
{
break;
}
}
The way I read that, it starts at a random moment between clock ticks,
and measures the time until the next tick. But if that's correct,
then 'clock_resolution' should vary randomly between 0 and .015625,
whereas it always seems to return .015 or .016 . Vadim, help?
Stepping back, I question whether this test is even useful in any way.
I think TimerTest::TestResolution() should just be eliminated.
- [lmi] Sporadic error in 'timer_test',
Greg Chicares <=