Cache object

JavaScript performance comparison

Revision 5 of this test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div class="search-results"></div>
<style>
 .search-results {
  display:none;
 }
 .visible { display:block !important; }
</style>
      
<script>
Benchmark.prototype.setup = function() {
  var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  $(".search-results").html("");

};

Benchmark.prototype.teardown = function() {
  $(".search-results").html("");

};
</script>

Preparation code output

<div class="search-results"></div> <style> .search-results { display:none; } .visible { display:block !important; } </style>

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
Without caching
$('.search-results').addClass('visible');

for (var i = 0; i < data.length; i++) {
  $('.search-results').append('<span>' + data[i] + '</span>');
}
pending…
With caching
var $search = $('.search-results');

$search.addClass('visible');

for (var i = 0; i < data.length; i++) {
  $search.append('<span>' + data[i] + '</span>');
}
pending…
Optimal Alina amazing version
var searchEl = document.querySelector('.search-results'),
  dataLength = data.length,
  newHtml = '',
  i = 0;
    
    while (i < dataLength) {
      newHtml += '<span>' + data[i] + '</span>';
      i++;
    }

    searchEl.innerHTML = newHtml;
    searchEl.className = 'search-results visible';
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