DOM Parsing vs regex

Benchmark created by patrick dw on


Preparation HTML

<div id='div1'></div>
<div id='div2'></div>
<script>
  var tableString = '<table><tr><td>table one</td></tr></table><table><tr><td>table two</td></tr></table>';
  var div1 = document.getElementById('div1');
  var div2 = document.getElementById('div2');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
DOM Parsing
var container = document.createElement('div');
container.innerHTML = tableString;

div1.appendChild(container.firstChild);
div2.appendChild(container.firstChild);
ready
regex
var tableEnd = '</table>';
var arr = tableString.split(tableEnd);

var t1 = arr[0].concat(tableEnd),
    t2 = arr[1].concat(tableEnd);

div1.innerHTML = t1;
div2.innerHTML = t2;
ready

Revisions

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

  • Revision 1: published by patrick dw on