What is more accurate than the new DateTime in a Dart web application?

Getting new is DateTimenot enough for me. The date object in the browser gives me milliseconds as an integer. I would like to get a time more accurate than a standard date object. Is it possible? How can i do this?

+5
source share
2 answers

Use window.performance.now()to get high resolution monotonous time. The function now()returns a colon with microseconds in fractional.

Here is an example:

import 'dart:html';

main() {
  var time = window.performance.now();
  print(time); // 12123.24341221
}

Please note that now()this is not a typical “time from the era”. Instead it is a delta from window.performance.timing.navigationStart.

The field is navigationStartdefined as (from spec ):

. , , fetchStart.

window.performance.now() , , DateTime.

requestAnimationFrame ( , ?), !

, animationFrame, :

Future<num> animationFrame;

:

gameLoop(num highResolutionTime) {
  // stuff
  window.animationFrame.then(gameLoop);
}

main() {
  window.animationFrame.then(gameLoop);
}
+5

, Stopwatch. ( ) .

var sw = new Stopwatch()..start();
doSomething();
print(sw.elapsed);
print(sw.elapsedMicroseconds);

( 2013 ) window.performance, bug . , .

+4

All Articles