create words array

Benchmark created by think49 on


Setup

var word = ['AB'], length = 1e6;

Test runner

Ready to run.

Testing in
TestOps/sec
while
var words = [], i = 1e6;
while (i--) words.push('AB');
ready
BaiBain1
var words = [],
    digits = (1e6).toString(2),
    i = 0,
    l = digits.length;

while (i++ < l) {
  words = words.concat(words);
  if (digits[i] === '1') {
    words.push('AB');
  }
}
ready
BaiBain2
var words = ['AB'],
    length = 1e6;

do {
  words = words.concat(words);
} while (words.length < length);

if (length < words.length) {
  words.slice(0, length);
}
ready
Array#join
var words = Array(1e6+1).join(',AB').split(',').slice(1);
 
ready

Revisions

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

  • Revision 1: published by think49 on