string repeatify test

Benchmark created by straybugs on


Preparation HTML

<script>
String.prototype.repeatify = String.prototype.repeatify || function(num) {
  var res = []
  
  if (typeof num === 'number') {
    while (num--) {
      res.push(this)
    }
    return res.join('')
  }
}


String.prototype.repeatify2 = String.prototype.repeatify2 || function(num) {
  var res = ""
  
  if (typeof num === 'number') {
    while (num--) {
      res += this
    }
    return res
  }
}

String.prototype.repeatify3 = String.prototype.repeatify3 || function(num) {
  var res = ""
  
  if (typeof num === 'number') {
    while (num--) {
      res = res.concat(this)
    }
    return res
  }
}
</script>

Setup

var times = 10000000;
    var str = 'love';

Test runner

Ready to run.

Testing in
TestOps/sec
repeatify
str.repeatify(times)
ready
repeatify2
str.repeatify2(times)
ready
repeatify3
str.repeatify3(times)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by straybugs on