var cache vs no cache

JavaScript performance comparison

Test case created by Sacha

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var text = 'hello this is my name oh yeah',
    result;
   
    String.prototype.truncate = String.prototype.truncate || function (length, substitute, fullwords) {
      return this.length > (length || 30) ? this.substr(0, (length || 30)).replace(/\s$/, '') + (substitute || '…') : this.toString();
    };
   
    String.prototype.truncate2 = String.prototype.truncate || function (length, substitute, fullwords) {
      var length = length || 30;
   
      return this.length > length ? this.substr(0, length).replace(/\s$/, '') + (substitute || '…') : this.toString();
    };
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
cache
result = text.truncate();
pending…
no cache
result = text.truncate2();
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

Add a comment