Timing accuracy in Flash
Does anyone know how accurate flash timing is and its ability to identify the client monitor's refresh rate? I need to be able to calculate time durations with up to 10 milliseconds accuracy of response time. Also if it is off, is there a way to possibly calibrate the response based on monitor refresh rate and action to make sure the value is as close to precise as possible? Any info would be great! Even better would be some examples of existing benchmark test.
Update:
I've found this post which is helpful but wanted to see if anyone else 开发者_JAVA百科has anything else to add on the subject.
AS3: How accurate are the getTimer() method and the Timer class?
http://www.kaourantin.net/2006/05/frame-rates-in-flash-player.html
No way to detect it, and the Flash Player doesn't use vsync so calculating update times wouldn't be of much use.
It all depends on what you want to use it for. If you're just timing something on screen, use getTimer as it's accurate to 1ms -- you absolutely don't need to know the monitor refresh rate for that.
Also, the Timer class is unreliable for calls so either roll your own timer class, or use getTimer on onEnterFrames (most accurate way to do screen updates).
You don't get monitor refresh rate from Flash, even in AIR. Yes, frames can render in different time (especially under heavy load). AFAIK, your best source of accurate time is getTimer(). Animation based on getTimer() in ENTER_FRAME is smooth (provided frame rate is high enough), although frame rate may vary.
Edit: Your code has chance to execute between frame changes, so set frame rate high and keep load small. This way you get more chances in time to respond. I believe the accuracy of getTimer() is up to 1 ms, but it is a little hard to check. Run program for few hours, then compare getTimer() and actual time passed?..
精彩评论