htmlEncodeStringReplacement (v45)

Revision 45 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="http://underscorejs.org/underscore.js"></script>
<script>
specialString = "\\$&";
</script>

Setup

var html = document.body.innerHTML;

Test runner

Ready to run.

Testing in
TestOps/sec
multiple replace()
return html.replace(/&/g, '&amp;', "g").replace(/"/g, '&quot;', "g").replace(/'/g, '&#39;', "g").replace(/</g, '&lt;', "g").replace(/>/g, '&gt;', "g");
ready
use jQuery
return $('<div/>').text(html).html();
ready
.innerHTML
return document.createElement('div').appendChild(document.createTextNode(html)).parentNode.innerHTML;
ready
_.escape()
return _.escape(html);
ready

Revisions

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