Property lookup price

JavaScript performance comparison

Test case created by grundmanise

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const push = Array.prototype.push;
  const bind = Function.prototype.bind;
  const random = Math.random;
  const object = { multiplier: 10 };
  const multiplier = object.multiplier;

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
With lookup
const array = [];

for (let i = 0; i < 1e6; i++) {
  array.push(Math.random() * object.multiplier);
}
pending…
No lookup
const array = [];
const bindedPush = bind.call(push, array);

for (let i = 0; i < 1e6; i++) {
  bindedPush(random() * multiplier);
}
pending…
With lookup (but cycle ref local property)
const array = [];

for (let i = 0; i < 1e6; i++) {
  array.push(Math.random() * multiplier);
}
pending…
No lookup (but with direct push)
const array = [];

for (let i = 0; i < 1e6; i++) {
  array.push(random() * multiplier);
}
pending…
No lookup (predeclared array)
const array = new Array(1e6);

for (let i = 0; i < 1e6; i++) {
  array[i] = (i * multiplier);
}
pending…
With lookup (predeclared array)
const array = new Array(1e6);

for (let i = 0; i < 1e6; i++) {
  array[i] = (i * object.multiplier);
}
pending…
With lookup (predeclared array, predeclared length)
const length = 1e6;
const array = new Array(length);

for (let i = 0; i < length; i++) {
  array[i] = (i * object.multiplier);
}
pending…
No lookup (predeclared array, predeclared length)
const length = 1e6;
const array = new Array(length);

for (let i = 0; i < length; i++) {
  array[i] = (i * multiplier);
}
pending…

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments