enzick-test

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="thinger" class="test"></div>
<div id="gizmo" class="test"></div>
<style>
.test { width:1px;height:1px;overflow:hidden;}
</style>
<script>
Benchmark.prototype.setup = function() {
    var tpl = '<p><span class="%s">i am %s %i</span></p>';
    var tplFn = function(str, i) {
          return tpl.replace(/%s/g, str).replace(/%i/g, i);
        }
    var i=0;
    $('#thinger').empty();
    $('#gizmo').empty();
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQ in Loop
for (i = 0; i <= 100; i++) {
  $('#thinger').append(
    '<p><span class="thinger">i am thinger ' + i + '</span></p>'
  );
  $('#gizmo').append(
    '<p><span class="gizmo">i am gizmo ' + i + '</span></p>'
  );
}
pending…
jQ outside Loop
var thinger = $('#thinger');
var gizmo = $('#gizmo');

for (i = 0; i <= 100; i++) {
  thinger.append(
    '<p><span class="thinger">i am thinger ' + i + '</span></p>'
  );
  gizmo.append(
    '<p><span class="gizmo">i am gizmo ' + i + '</span></p>'
  );
}
pending…
String Replace
var thingerDom = [];
var gizmoDom = [];

for (i = 0; i <= 100; i++) {
  thingerDom.push(tplFn('thinger', i));
  gizmoDom.push(tplFn('gizmo', i));
}

$('#thinger').append(thingerDom.join(''));
$('#gizmo').append(gizmoDom.join(''));
pending…
No Replace
var thingerDom = [];
var gizmoDom = [];

for (i = 0; i <= 100; i++) {
  thingerDom.push('<p><span class="gizmo">i am gizmo ' + i + '</span></p>');
  gizmoDom.push('<p><span class="thinger">i am thinger ' + i + '</span></p>');
}

$('#thinger').append(thingerDom.join(''));
$('#gizmo').append(gizmoDom.join(''));
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. Here’s a list of current revisions for this page:

0 comments

Add a comment