Replace entities

Benchmark created by Giulia on


Preparation HTML

<script>
  t = "&quot; &apos; &lt; &gt;&quot;";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Case 1
var a = new Array({
 f: /&quot;/gi,
 r: "\42"
}, {
 f: /&apos;/gi,
 r: "\u0027"
}, {
 f: /&lt;/gi,
 r: "\74"
}, {
 f: /&gt;/gi,
 r: "\76"
}),
    b = a.length;
while (b--) {
 t = t.replace(a[b].f, a[b].r);
}
ready
Case 2
var a = new Array({
 f: "&quot;",
 r: "\42"
}, {
 f: "&apos;",
 r: "\u0027"
}, {
 f: "&lt;",
 r: "\74"
}, {
 f: "&gt;",
 r: "\76"
}),
    b = a.length;
while (b--) {
 c = new RegExp(a[b].f, "gi");
 t = t.replace(c, a[b].r);
}
ready

Revisions

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