sdz_closure_exemple

JavaScript performance comparison

Test case created by sdz_closure_exemple

Preparation code

<div id="description" style="height:30px; overflow:hidden;">
</div>
<div id="description2" style="height:30px; overflow:hidden;">
</div>
      
<script>
Benchmark.prototype.setup = function() {
  var addDescription = function(texteDescription) {
      var baliseDescription = document.getElementById('description'); //appel au DOM
      var child = document.createElement('p');
      child.innerHTML = texteDescription;
      baliseDescription.appendChild(child);
      }
      
  var addDescription2 = (function() {
    var baliseDescription = document.getElementById('description2'); //appel au DOM
    return function(texteDescription) {
      var child = document.createElement('p');
      child.innerHTML = texteDescription;
      baliseDescription.appendChild(child);
    }
  })();

};
</script>

Preparation code output

<div id="description" style="height:30px; overflow:hidden;"> </div> <div id="description2" style="height:30px; overflow:hidden;"> </div>

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
sans closure
addDescription('première description');
pending…
avec closure
addDescription2('première description');
pending…

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

Compare results of other browsers

0 Comments