cancel
Showing results for 
Search instead for 
Did you mean: 

Microseconds in XSJS

Former Member
0 Kudos
138

Hello,

i'm facing one problem. My client has this code in php

$start_time = microtime(true); // with this you get the current timestamp with microseconds

//code to meassure it's performance here...

...

$time = microtime(true) - $start_time;

So they want to meassure how long it takes to execute the code.

But a microseconds precission will be needed...

I've tried with Date(), CURRENT_TIMESTAMP and now(), but all i get is milliseconds precission...

Is there a way to implement the above code in XSJS??

Best regards,

Luis.

View Entire Topic
thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

This is a limitation of JavaScript itself, not XSJS necessarily.  In JavaScript the now() object only returns milliseconds. For client side timing browsers are starting to expose internal timers that go lower than milli, but these are exposed via the Window object since they aren't coming from JavaScript itself:

http://gent.ilcore.com/2012/06/better-timer-for-javascript.html

This therefore wouldn't be accessible in a server side implementation of SpiderMonkey.

Even Node.js has a similar problem from JavaScript itself. It therefore has to use the process object to get more accurate timings:

process.hrtime()

Former Member
0 Kudos

Yes, that's the conclussion I got to, searching on the web...but I asked just to be sure.

Thank you very much for your response, Thomas.

Best regards,

Luis.