Get time in nanoseconds with ActionScript 3

Hi, I am trying to get the current time, including nanoseconds in actionscript 3 for use in flex 4.5. Anyone who can help me?
+4
source share
6 answers

ActionScript does not provide an accurate timer.

+7
source

The smallest measure of time available in Flash Player is milliseconds.

To get the current time, simply create a new Date object:

 var currentTime:Date = new Date(); 

See the Date class documentation here .

+9
source

I think that a shared computer does not support a smaller temporary measure, and then millions.

0
source

I'm not sure anyone has already done this, but you can create a Socket NTP server interface.

You do not need to implement the entire protocol; you can just do what ntpdate does to capture time. A lot of time has passed since I worked directly with the protocol, but I do not think this task is so difficult.

0
source

You canโ€™t get non-dual in Flex, in fact there are not many languages โ€‹โ€‹that provide nanoseconds as results in a period of time. The most you could get is a tick, which is mainly provided for languages โ€‹โ€‹using native code, but they are not provided directly for scripting languages.

It would be best to have a difference in milliseconds and simply scale the result in the test as something more than a longer time (for example, 10 or even 100 times more tests), which will significantly bring the results closer to expected.

0
source

When I tried to measure something in microseconds, I looped it 1000 times and subtracted the time for the time that the actual cycle 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 think you can loop 1,000,000 times to get nanoseconds, but you have to wait a while to complete the loop.

0
source

All Articles