htmlEncodeRegEx
JavaScript performance comparison
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
var html = document.body.innerHTML;
var map = {
"&": "&",
"'": "'",
'"': """,
"<": "<",
">": ">"
};
var tempElement = $(document.createElement("div"));
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
multiple replace() |
|
pending… |
single replace with map |
|
pending… |
single replace with switch |
|
pending… |
use jQuery |
|
pending… |
use jQuery with pre-created element |
|
pending… |
.innerHTML |
|
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:
- Revision 1: published by yuval
- Revision 2: published
- Revision 3: published
- Revision 5: published
- Revision 6: published
- Revision 7: published
- Revision 8: published by Eamon Nerbonne
- Revision 9: published
- Revision 11: published
- Revision 14: published by Yuval
- Revision 15: published by Ian Obermiller
- Revision 16: published by ThinkingStiff
- Revision 17: published by ThinkingStiff
- Revision 18: published
- Revision 20: published by Prestaul
0 comments