decodeHTML

JavaScript performance comparison

Revision 2 of this test case created by Nathan Perry

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function getDiv(){
      return document.createElement('div');
    };
   
    function decodeHTML(input){
      var e = getDiv().cloneNode(false);
      e.innerHTML = input;
      return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
    };
   
    function decodeHTML2(input){
      var e = document.createElement('div');
      e.innerHTML = input;
      return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
    };
   
    var unique = document.createElement('div');
    function decodeHTML3(input){
      unique.innerHTML = input;
      return unique.childNodes.length === 0
        ? ""
        : unique.childNodes[0].nodeValue;
    };
   
    var unique4 = null;
    function decodeHTML4(input){
      if (!unique4)
        unique4 = document.createElement('div');
      unique4.innerHTML = input;
      return unique4.childNodes.length === 0
        ? ""
        : unique4.childNodes[0].nodeValue;
    };
   
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
clone
decodeHTML("&lt;img src='myimage.jpg'&gt;");
pending…
not cloned
decodeHTML2("&lt;img src='myimage.jpg'&gt;");
pending…
unique div
decodeHTML3("&lt;img src='myimage.jpg'&gt;");
pending…
unique div (2)
decodeHTML4("&lt;img src='myimage.jpg'&gt;");
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment