Date.prototype.getTime

P T Withington ptw at pobox.com
Tue Jun 27 14:38:38 PDT 2006


AFAICT the canonical way to measure elapsed time in ECMAScript  
requires taking the difference between two expressions of the form:

(new Date).getTime()

On the Mac SWF plug-in, this expression yields a value that appears  
to have 10us precision (ms as a float with 2 digits of precision).   
On the Windows SWF plug-in, and the Mozilla Javascript engine, this  
expression yields a value with only ms precision (as if it had been  
processed by TimeClip).

I am wondering if the new standard should encourage implementors to  
return a value with as much precision as the underlying hardware/OS  
permits?  (And to optimize this idiom, which on the face of it looks  
quite expensive:  creating a Date object only to extract the value  
attribute and discard the object.)

Or, is there already a better, more accurate way to measure elapsed  
time?  Or, should there be?



More information about the Es4-discuss mailing list