开发者

Get the time in nanoseconds with actionscript 3

开发者 https://www.devze.com 2023-03-09 00:47 出处:网络
Hi I\'m trying to get the current time including 开发者_如何学Gothe nanoseconds in actionscript 3 for use in flex 4.5.

Hi I'm trying to get the current time including 开发者_如何学Gothe nanoseconds in actionscript 3 for use in flex 4.5. Anyone that can help me out?


The smallest time measure available in Flash Player is milliseconds.

To get current time just create new Date object:

var currentTime:Date = new Date();

See more documentation of Date class here.


ActionScript doesn't expose a timer that precise.


I think commont computer don't support smaller time measure then mileseconds


I am not sure if anyone has done this already, but you could create a Socket interface to an NTP server.

You don't need to implement the whole protocol; you could just do what ntpdate does to grab the time. It has been a very long time since I worked directly with the protocol, but I don't think this task is that hard.


You can not get nonseconds in Flex, actually there is not much languages out there providing nanoseconds as results into the timespan. The most u could get is "ticks" which is mostly provided for languages with native code execution, but it is not provided directly to a scripting languages.

The best would be to have miliseconds difference, and just scale the result into the benchmark something like a longer running time ( like 10 or even 100x more tests ) which will bring results much closer to the expecting ones.


When I tried to measure something in microseconds I looped it 1000 times and subtracted the time by the the time the actual for-loop takes. And I would get something close to microseconds.

var startTime:int = new Date().valueOf();
for(var ii = 0;ii<1000;ii++)
{
    //do something here     
}
var endTime:int = new Date().valueOf();
trace(endTime-startTime);

I guess you can loop 1 000 000 times in order to get nanoseconds but you will have to wait some time for the loop to finish.

0

精彩评论

暂无评论...
验证码 换一张
取 消