Hi Bill,
I tried to reproduce what you're seeing by modifying the IceGrid\icebox demo (a very simple demo). I just added a timer to the client:
Code:
class Task : public IceUtil::TimerTask
{
public:
Task() :
_lastTime(IceUtil::Time::now()),
_count(0)
{
}
virtual void runTimerTask()
{
IceUtil::Time diff = IceUtil::Time::now() - _lastTime;
if(_min == IceUtil::Time() || diff < _min)
{
_min = diff;
}
if(_max == IceUtil::Time() || diff > _max)
{
_max = diff;
}
_total += diff;
_lastTime += diff;
_count++;
}
virtual ~Task()
{
cerr << "Count = " << _count << endl;
cerr << "Min = " << _min.toDuration() << endl;
cerr << "Max = " << _max.toDuration() << endl;
cerr << "Avg = " << (_total / _count).toDuration() << endl;
}
private:
IceUtil::Time _lastTime;
IceUtil::Time _min;
IceUtil::Time _max;
IceUtil::Time _total;
int _count;
};
int
HelloClient::run(int argc, char* argv[])
{
// ...
IceUtil::TimerTaskPtr task = new Task;
IceUtil::TimerPtr timer = new IceUtil::Timer;
timer->scheduleRepeated(task, IceUtil::Time::milliSeconds(5));
IceUtil::ThreadControl().sleep(IceUtil::Time::seconds(30));
timer->destroy();
// ...
}
and shockingly, got about 15 to 16 ms for each run. I also tried different periods (1ms, 10ms, 50ms), with each time an "overhead" of 10 to 12ms. Running the server part of this demo or not runningit didn't change anything. Likewise, running this code as administrator or myself didn't a difference. (I tried all this on Windows 7 x64 with VS2008 - not Windows Embedded 7 x64).
It turns out that the issue is the default clock, which is has a very poor resolution on Windows. Switching to the Monotonic clock fixed the problem:
Code:
class Task : public IceUtil::TimerTask
{
public:
Task() :
_lastTime(IceUtil::Time::now(IceUtil::Time::Monotonic)),
_count(0)
{
}
virtual void runTimerTask()
{
IceUtil::Time diff = IceUtil::Time::now(IceUtil::Time::Monotonic) - _lastTime;
if(_min == IceUtil::Time() || diff < _min)
{
_min = diff;
}
if(_max == IceUtil::Time() || diff > _max)
{
_max = diff;
}
_total += diff;
_lastTime += diff;
_count++;
}
virtual ~Task()
{
cerr << "Count = " << _count << endl;
cerr << "Min = " << _min.toDuration() << endl;
cerr << "Max = " << _max.toDuration() << endl;
cerr << "Avg = " << (_total / _count).toDuration() << endl;
}
private:
IceUtil::Time _lastTime;
IceUtil::Time _min;
IceUtil::Time _max;
IceUtil::Time _total;
int _count;
};
With Monotonic, I get the expected result (5ms for min, max and average).
With the default clock (Realtime), Ice uses ftime, while with the Monotomic clock, Ice uses the high-resolution performance counter.
Can you double-check how you measure time? And if you still get a strange result, can you attach a code sample?
Thanks,
Bernard