Deprecated: Assigning the return value of new by reference is deprecated in /home/ernestd/ernestdelgado.com/archive/wp-settings.php on line 232

Deprecated: Assigning the return value of new by reference is deprecated in /home/ernestd/ernestdelgado.com/archive/wp-settings.php on line 234

Deprecated: Assigning the return value of new by reference is deprecated in /home/ernestd/ernestdelgado.com/archive/wp-settings.php on line 235

Deprecated: Assigning the return value of new by reference is deprecated in /home/ernestd/ernestdelgado.com/archive/wp-settings.php on line 252

Deprecated: Assigning the return value of new by reference is deprecated in /home/ernestd/ernestdelgado.com/archive/wp-includes/cache.php on line 36

Deprecated: Assigning the return value of new by reference is deprecated in /home/ernestd/ernestdelgado.com/archive/wp-includes/query.php on line 15

Deprecated: Assigning the return value of new by reference is deprecated in /home/ernestd/ernestdelgado.com/archive/wp-includes/theme.php on line 505

Notes

Take them as Lorem Ipsum

Benchmark on the Floor

Feb 04, 2009

In the projects I have been working lately I've had to test the speed of a bunch of JavaScript functions. That was another good excuse for me to read more about different ways of creating benchmarks that I didn't know of.

There's one test I want to mention here as it uses those obscure JavaScript syntax tricks that I like so much.

The goal of this test was to find a faster way to run the Math.floor function to see if we could make some heavy loops of our scripts even faster. Here is where the bitwise operators come into the game. I saw the "~~" trick in a forum thread and I found another two playing for a while with the JavaScript console (all of them round a number the same way). The average of all the A-Grade browsers tests gives us the following results:

  • Math.floor(n): 15.804
  • ~~n: 8.784
  • n|n: 8.081
  • n&n: 12.019

(Average time per instruction in microseconds)

Apparently, the n|n option will be the best candidate for our purpose. You can test it yourself in your browser:




View all notes...