decodeHTML
JavaScript performance comparison
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;
};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
clone |
|
pending… |
not cloned |
|
pending… |
unique div |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments