Script Preparation code:
x
 
function repeatify(string, repetitions) {
   if (repetitions < 0 || repetitions === Infinity) {
      throw new RangeError('Invalid repetitions number');
   }
 
   let result = '';
 
   for (let i = 0; i < repetitions; i++) {
      result += string;
   }
 
   return result;
}
function repeatifyWithArrayAndJoin(string, repetitions) {
   if (repetitions < 0 || repetitions === Infinity) {
      throw new RangeError('Invalid repetitions number');
   }
 
   const result = [];
 
   for (let i = 0; i < repetitions; i++) {
      result.push(string);
   }
 
   return result.join('');
}
function repeatifyWithNewArray(string, repetitions) {
   if (repetitions < 0 || repetitions === Infinity) {
      throw new RangeError('Invalid repetitions number');
   }
  
   return new Array(repetitions).join(string);
}
function _checkRepeations(repetitions) {
    if (repetitions < 0 || repetitions === Infinity) {
      throw new RangeError('Invalid repetitions number');
   }
}
function repeatifyWithNewArrayAndExternalThrow(string, repetitions) {
   _checkRepeations(repetitions);
  
   return new Array(repetitions).join(string);
}
function repeatifyWithNewArrayAndExternalThrowWithProps(string, repetitions) {
   this.checkRepeations(repetitions);
  
   return new this.Array(repetitions).join(string);
}
var ctx = {
    checkRepeations: _checkRepeations,
    Array: Array
}
repeatifyWithNewArrayAndExternalThrowWithProps = repeatifyWithNewArrayAndExternalThrowWithProps.bind(ctx);
var TEST_STRING = 'home, sweet home';
var COUNT = 1e6;
Tests:
  • native repeat

     
    TEST_STRING.repeat(COUNT);
  • stupid repeatify

     
    repeatify(TEST_STRING, COUNT);
  • repeatifyWithArrayAndJoin

     
    repeatifyWithArrayAndJoin(TEST_STRING, COUNT);
  • repeatifyWithNewArray

     
    repeatifyWithNewArray(TEST_STRING, COUNT);
  • repeatifyWithNewArrayAndExternalThrow

     
    repeatifyWithNewArrayAndExternalThrow(TEST_STRING, COUNT);
  • repeatifyWithNewArrayAndExternalThrowWithProps

     
    repeatifyWithNewArrayAndExternalThrowWithProps(TEST_STRING, COUNT);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    native repeat
    stupid repeatify
    repeatifyWithArrayAndJoin
    repeatifyWithNewArray
    repeatifyWithNewArrayAndExternalThrow
    repeatifyWithNewArrayAndExternalThrowWithProps

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 8 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2952.0 Safari/537.36
Chrome 57 on Mac OS X 10.11.6
View result in a separate tab
Test name Executions per second
native repeat 2025898.0 Ops/sec
stupid repeatify 10.2 Ops/sec
repeatifyWithArrayAndJoin 12.5 Ops/sec
repeatifyWithNewArray 58.9 Ops/sec
repeatifyWithNewArrayAndExternalThrow 60.6 Ops/sec
repeatifyWithNewArrayAndExternalThrowWithProps 61.8 Ops/sec