Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsecond resolution of performance.now() and Stopwatch #9565

Closed
DartBot opened this issue Apr 1, 2013 · 10 comments
Closed

Microsecond resolution of performance.now() and Stopwatch #9565

DartBot opened this issue Apr 1, 2013 · 10 comments
Labels
closed-as-intended Closed as the reported issue is expected behavior web-libraries Issues impacting dart:html, etc., libraries

Comments

@DartBot
Copy link

DartBot commented Apr 1, 2013

This issue was originally filed by @bp74


What steps will reproduce the problem?

I think this is more a Dartium bug, but still ...

import 'dart:html';

void main() {
  var sw = new Stopwatch()..start();
  var pn = window.performance.now();
  
  for(int i = 0; i< 100000; i++);
  
  var d1 = sw.elapsedMicroseconds;
  var d2 = 1000 * (window.performance.now() - pn);
  
  print(d1);
  print(d2);
}

What is the expected output? What do you see instead?

You get microseconds, but the resolution is milliseconds. So it doesn't make much sense. This little program prints:

1000
999.9999999763531

What version of the product are you using? On what operating system?

Dart Editor version 0.1.2_r20718
Dart SDK version 0.1.2.0_r20702

Please provide any additional information below.

@DartBot
Copy link
Author

DartBot commented Apr 1, 2013

This comment was originally written by @bp74


Maybe it's important to add that this is on a Windows 7 64 bit machine.

@DartBot
Copy link
Author

DartBot commented Apr 1, 2013

This comment was originally written by @bp74


Okay i did some more tests, dependent on the browser you get different results:

IE 9: error because performance.now() does not exist.
IE 10: microsecond precision (!!!)
Dartium: millisecond precision
Chrome 26: millisecond precision
Chrome 28.0.1458.0: millisecond precision
Firefox 19: microsecond precision (!!!)

So only IE10 and Firefox 19 work as expected (on Windows 7) but not WebKit browsers.

@sethladd
Copy link
Contributor

sethladd commented Apr 1, 2013

cc @blois.
Added Area-HTML, C2, Triaged labels.

@blois
Copy link
Contributor

blois commented Apr 1, 2013

Not quite sure I follow-
I'm seeing microsecond resolution from Stopwatch in Dartium and millisecond resolution from Stopwatch in all dart2js.

I'm seeing window.performance.now as microseconds in all supported cases.

Is the request that Stopwatch use window.performance.now in dart2js when possible?

@DartBot
Copy link
Author

DartBot commented Apr 1, 2013

This comment was originally written by @bp74


If you call window.performance.now() several times, you get this times:
216.999999996915
182.99999999726424
167.00000000128057
198.00000000395812
199.00000000052387

the now() function should give you milliseconds but with a microsecond resolution. The problem is that it does not give you the fraction of the millisecond. The fraction is always 000 or 999.

The same happens with a Stopwatch. The Stopwatch class has a "microseconds" property, but the value is always a multiple of 1000.

@DartBot
Copy link
Author

DartBot commented Apr 1, 2013

This comment was originally written by @bp74


Here is another example to make it clearer:

import 'dart:html';
void main() {
  document.onClick.listen((e) {
    print(window.performance.now());
  });
}

If you continuously click on the document, you get this result:

1032.999999995809
1656.9999999992433
2417.0000000012806
3152.9999999984284
3896.999999997206
4392.999999996391

window.performance.now() should give you milliseconds, but the fraction should give you microseconds.

@blois
Copy link
Contributor

blois commented Apr 1, 2013

I'm able to repro this on Chrome Windows, but not Linux.

I assume it's running into this Chrome bug https://code.google.com/p/chromium/issues/detail?id=158234

Resolving as 'As Designed' as I believe the Dart functionality is performing properly, but it's limited by the underlying Chrome implementation.


Added AsDesigned label.

@sethladd
Copy link
Contributor

sethladd commented Apr 2, 2013

FWIW it seems like windows.performance.now() works better on Mac:

7781.259999999747
60464.874000001146
69156.95100000084
74710.68999999989

@DartBot
Copy link
Author

DartBot commented Jun 9, 2014

This comment was originally written by Misko.H...@gmail.com


pete> Is the request that Stopwatch use window.performance.now in dart2js when possible?

Yes, I think that is the request. We should be using high resolution timer whenever possible.

@blois
Copy link
Contributor

blois commented Jun 9, 2014

Stopwatch does use window.performance.now when available (all but Safari).

@DartBot DartBot added Type-Defect web-libraries Issues impacting dart:html, etc., libraries closed-as-intended Closed as the reported issue is expected behavior labels Jun 9, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-as-intended Closed as the reported issue is expected behavior web-libraries Issues impacting dart:html, etc., libraries
Projects
None yet
Development

No branches or pull requests

3 participants