Hacker News new | ask | show | jobs
by bzbarsky 2364 days ago
Are you running that in a web page, or in the devtools console?

I just tried running it in a web page, with the last line replaced by `console.log(performance.now() - t0);` and on my hardware it finishes in ~1.5 seconds in Firefox and ~2 seconds in Chrome.

Similar if I run it in a devtools console like so:

    (function() {
      var arr = new ArrayBuffer(4)
      var arrInt = new Uint32Array(arr)
      t0 = performance.now(); for (; arrInt[0] <= 1000000000; ++arrInt[0]) {} ; 
    })();
    performance.now() - t0
and hence avoid the undeclared global variable accesses. If I run the original code in the devtools console, it is in fact quite slow in Firefox, because global variable access is slower in the devtools console there. So each get of `arrInt` takes a quite long time. That's https://bugzilla.mozilla.org/show_bug.cgi?id=793345 and I suspect that's what you're running into here.

The main moral is to not do performance testing in the console, because it's a _very_ different execution environment from actual web pages.

1 comments

> in the devtools console

Wow, you are right, thanks. Lesson learned.