System.Diagnostics.Process.UserProcessorTime is inaccurate

Call System.Diagnostics.Process.UserProcessorTime.TotalMilliseconds in update, I found the time is far delayed than real time elapse.

var now = _this_process.UserProcessorTime.TotalMilliseconds;
if (now - _last >= 5000)
{
_last = now;
f();
}

In PC, f() called every 5 secs. But in android, f() will delay (about 10 secs to 1 min, seems random)

Is it a bug of unity?

Probably not.

https://msdn.microsoft.com/en-us/library/system.diagnostics.process.userprocessortime(v=vs.110).aspx says UserProcessorTime doesn’t measure the time elapsed

As the name indicates, it’s user processor time. Not real time. The use case is pretty narrow and absolutely not ever to be used for general timers. You could just use Time.time, but note code like you posted will stop working after a few days due to single-precision floating point limitations. Better to have a timer that starts at 0.0, counts up to 5.0, then resets. (Typically code wouldn’t run for days, but why have potential bugs when it’s just as easy to avoid them.)

–Eric