logging-string-closure

JavaScript performance comparison

Revision 2 of this test case created by J. Ryan Stinnett

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var output = [];

};
</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
String
var log = false;

function dumpv(str) {
  if (log) {
    console.log(str);
  }
}

for (var i = 0; i < 1000; i++) {
  output.push(i);
  dumpv("Output:" + i);
}
pending…
Closure
var log = false;

function dumpv(func) {
  if (log) {
    console.log(func());
  }
}

for (var i = 0; i < 1000; i++) {
  output.push(i);
  dumpv(function() { return "Test:" + i; });
}
pending…
Control
for (var i = 0; i < 1000; i++) {
  output.push(i);
}
pending…
String (inline test)
var log = false;

function dumpv(str) {
  if (log) {
    console.log(str);
  }
}

for (var i = 0; i < 1000; i++) {
  output.push(i);
  if (log) {
    dumpv("Output:" + i);
  }
}
pending…
Closure (inline test)
var log = false;

function dumpv(func) {
  if (log) {
    console.log(func());
  }
}

for (var i = 0; i < 1000; i++) {
  output.push(i);
  if (log) {
    dumpv(function() { return "Test:" + i; });
  }
}
pending…
Arrow Closure
var log = false;

function dumpv(func) {
  if (log) {
    console.log(func());
  }
}

for (var i = 0; i < 1000; i++) {
  output.push(i);
  dumpv(() => "Test:" + i);
}
pending…

Compare results of other browsers

Revisions

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

0 Comments