str_repeat (phpjs)

Benchmark created by w35l3y on


Setup

function str_repeat1(input, multiplier) {
      var y = '';
      while (true) {
        if (multiplier & 1) {
          y += input;
        }
        multiplier >>= 1;
        if (multiplier) {
          input += input;
        } else {
          break;
        }
      }
      return y;
    }
    
    function str_repeat2(string, multiplier) {
    multiplier = parseInt((multiplier === true ? 1 : multiplier) + "", 10);
    return typeof string == "string" && multiplier >= 1 ?
    new Array(multiplier + 1).join(string) : null;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
kvz (100)
str_repeat1("-=", 100)
ready
n41tkd (100)
str_repeat2("-=", 100)
ready
kvz (1000)
str_repeat1("-=", 1000)
ready
n41tkd (1000)
str_repeat2("-=", 1000)
ready
kvz (10000)
str_repeat1("-=", 10000)
ready
n41tkd (10000)
str_repeat2("-=", 10000)
ready

Revisions

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