inject vs apply

JavaScript performance comparison

Revision 7 of this test case created by Lucas

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://rawgit.com/israelidanny/veinjs/master/vein.js"></script>
<div id="container"></div>

      
<script>
Benchmark.prototype.setup = function() {
  $container = $('#container');
  
  for(var i=0;i<25;i++){
     $container.append($('<h1 class="myHeader">My Header</h1>'));
  }
  
  // Cache selector.
  $headers = $('h1.myHeader');

};

Benchmark.prototype.teardown = function() {
  $headers.remove();
  vein.inject('h1.myHeader', null);

};
</script>

Preparation code output

<div id="container"></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
Application
$headers.css({'color': 'red', 'font-size': '3em'});
pending…
Injection
vein.inject('h1.myHeader', {'color': 'red', 'font-size': '3em'});
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