Glue a string together

Benchmark created by Wouter on


Setup

var fibonacci = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765];

Test runner

Ready to run.

Testing in
TestOps/sec
String concatenate
// source: https://developers.google.com/speed/articles/optimizing-javascript?hl=en#working-with-strings

var fibonacciStr = 'First 20 Fibonacci Numbers\n';
for (var i = 0; i < 20; i++) {
  fibonacciStr += i + ' = ' + fibonacci[i] + '\n';
}
ready
Array join
// source: https://developers.google.com/speed/articles/optimizing-javascript?hl=en#working-with-strings

var strBuilder = ['First 20 fibonacci numbers:'];
for (var i = 0; i < 20; i++) {
  strBuilder.push(i, ' = ', fibonacci[i]);
}
var fibonacciStr = strBuilder.join('\n');
ready

Revisions

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

  • Revision 1: published by Wouter on