Skip to content

In ts.performance.now, bind window.performance.now #9956

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

Merged
merged 1 commit into from
Jul 26, 2016

Conversation

sandersn
Copy link
Member

Fixes #9954

Using an arrow function. Previously, it was set directly to window.performance.now, which fails when used in Chrome.

Using an arrow function. Previously, it was set directly to
window.performance.now, which fails when used on Chrome.
@sandersn
Copy link
Member Author

Incidentally, I ripped off Date.now in both Chrome and Node and it works fine that way.

@weswigham
Copy link
Member

👍 It's always a little disappointing how inconsistent the web is with what you can rip off its hosting object and what you cannot.

@sandersn
Copy link
Member Author

And neither Date nor performance document it, in the documentation I found at least.

@weswigham
Copy link
Member

@sandersn That was why I thought it was okay to rip both off. 😞

@sandersn
Copy link
Member Author

One of the Mac builds timed out. I think it's OK to merge anyway.

@sandersn sandersn merged commit 670f0c9 into master Jul 26, 2016
@sandersn sandersn deleted the bind-window-performance-now branch July 26, 2016 18:31
@weswigham
Copy link
Member

@sandersn This has been happening every few builds - I actually restarted a build last night that had been running for over an hour (I just assumed travis had hung). I don't know if it's a random pathological perf problem in TS that's only exposed on mac, or an issue with the travis infrastructure.

@weswigham weswigham removed their assignment Jul 26, 2016
@mihailik
Copy link
Contributor

FYI: compared () => performance.now() with performance.now.bind(performance), the arrow function is faster on my Chrome, faster in FireFox — but slower on IE11.

Don't have an Edge to try.

Here's the code below to run in DevTools console:

var runAndAgain = function() {
  setTimeout(function() {
    runMillion();
    runAndAgain();
  }, 1);
};
runAndAgain();

function runMillion() {

  var now_arrow = function() { return performance.now(); };
  var now_bind = performance.now.bind(performance);

  var start = new Date(), tmp=0;
  for (var i = 0; i < 1000000; i++) { tmp = now_arrow(); }
  var arrow_time = new Date() - start;

  var start = new Date(), tmp=0;
  for (var i = 0; i < 1000000; i++) { tmp = now_bind(); }
  var bind_time = new Date() - start;

  console.log('arrow '+arrow_time+'\tbind '+bind_time+'\t ratio '+(((10000*arrow_time/bind_time)|0)/100)+'%');
}

@sandersn
Copy link
Member Author

Does anybody use IE11 to debug TypeScript? Faster in Chrome is better in my book.

@weswigham
Copy link
Member

AFAIK, most of the team doesn't use IE, so the faster in chrome/FF option does seem better.

@mihailik
Copy link
Contributor

I totally agree, Chrome is a better target -- and the difference is small enough anyway. Only wanted to give more context 👍

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants