Dynatable Prototypal Refactor

JavaScript performance comparison

Test case created by Steve Schwartz

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://s3.amazonaws.com/s3.alfajango.com/jsperf/dynatable-refactor/jquery.dynatable-0.0.2.js"></script>
<script src="https://s3.amazonaws.com/s3.alfajango.com/jsperf/dynatable-refactor/jquery.dynatable-0.0.3.js"></script>

<div id="container"></div>
      
<script>
Benchmark.prototype.setup = function() {
  var numTables = 20,
      tables = [];
  function randomString(length) {
    var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
        result = '';
    for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
    return result;
  }
  
  for (var t = 0; t < numTables; t++) {
    var numColumns = 5,
        numRows = 10,
        rows = [], columns = [];
  
    for (var i = 0; i < numColumns; i++) {
      columns.push('<th>Column ' + i + '</th>');
    }
  
    for (var i = 0; i < numRows; i++) {
      var data = [];
      for (var n = 0; n < numColumns; n++) {
        data.push(randomString(16));
      }
      rows.push('<tr><td>' + data.join('</td><td>') + '</td></tr>');
    }
  
    tables.push('<table id="test-table-' + t + '" class="test-table"><thead><tr>' + columns.join() + '</tr><tbody>' + rows.join() + '</tbody></table>');
  }
  $('#container').html(tables.join());

};

Benchmark.prototype.teardown = function() {
  $('.test-table').remove();
  $('#container').html('');

};
</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
Init - Dynatable Old
$('.test-table').dynatable();
pending…
Init - Dynatable Refactored
$('.test-table').dynatable003();
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