Reputation: 952
Hi I'm trying to get the current time including the nanoseconds in actionscript 3 for use in flex 4.5. Anyone that can help me out?
Upvotes: 4
Views: 5560
Reputation: 171
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.
Upvotes: 0
Reputation: 2604
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.
Upvotes: 0
Reputation: 2941
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.
Upvotes: 0
Reputation: 3731
I think commont computer don't support smaller time measure then mileseconds
Upvotes: 0
Reputation: 14221
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.
Upvotes: 9