String.link HTML Escapement

JavaScript performance comparison

Test case created by Jason Miller

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var div = document.createElement('div');
    var properValue = "foo&lt;&gt;&#039;&quot;";
    var value;
};
</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
String#link
value = String.prototype.link("foo<>'\"").split('"')[1];
if (value!==properValue) {
  throw("Incorrect: "+value+" !== "+properValue);
}
pending…
innerText<>innerHTML
div.textContent = "foo<>'\"";
value = div.innerHTML;
if (value!==properValue) {
  console.log(value, properValue);
  throw("Incorrect: "+value+" !== "+properValue);
}
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