String building (v5)

Revision 5 of this benchmark created by bla on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="result">

</div>

Setup

var append_string = "abc";

Test runner

Ready to run.

Testing in
TestOps/sec
Build and then create element not in DOM
var result = "";
for (var i = 0; i < 1000; i++) {
  result += append_string;
}
$('<div/>').html(result)
ready
Append to element that isn't in the DOM yet using +=
var result = $('<div/>');
result.innerHTML = '';
for (var i = 0; i < 1000; i++) {
  result.innerHTML += append_string;
}
ready
use jquery 'append' to element not in dom
var result = $('<div/>');
for (var i = 0; i < 1000; i++) {
  result.append(append_string);
}
ready
var result = $('<div/>');
var newx;
for (var i = 0; i < 1000; i++) {
  newx += append_string; 
}

result.innerHTML = newx;
ready

Revisions

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