Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Chrome 63
Mac OS X 10.12.6
Other
2025 years ago
Test name Executions per second
1 118896.9 Ops/sec
2 220548.9 Ops/sec
3 653321.2 Ops/sec
4 35374.7 Ops/sec
Tests:
  • 1

    x
     
    String.prototype.repeatify = function(numTimes) {
      let result = this;
      for (let i = 0; i < numTimes - 1; i++) {
        result += this;
      }
      return result;
    };
    'test'.repeatify(100);
  • 2

     
    String.prototype.repeatify = function(numTimes) {
      return new Array(numTimes + 1).join(this);
    };
    'test'.repeatify(100);
  • 3

     
    String.prototype.repeatify = function(numTimes) {
      return new Array(3).fill(this).join('');
    };
    'test'.repeatify(100);
  • 4

     
    String.prototype.repeatify = function(numTimes) {
      var strArray = [this];
      for (var i = 0; i < numTimes - 1; i++) {
        strArray.push(this);
      }
      return strArray.join('');
    };
    'test'.repeatify(100);