htmlEncodeRegEx
JavaScript performance comparison
Preparation code
<script src="https://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"));
var arr = [
[/&/g, '&'],
[/'/g, '''],
[/"/g, '"'],
[/</g, '<'],
[/>/g, '>']
];
var better_map_fn = function(c) {
return map[c];
};
var el_10 = 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… |
string replace with array map
|
|
pending… |
better map replace
|
|
pending… |
vanilla element method
|
|
pending… |
vanilla element method, with precreated element
|
|
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.
- Revision 1: published yuval
- Revision 2: published
- Revision 3: published
- Revision 5: published
- Revision 6: published
- Revision 7: published
- Revision 8: published Eamon Nerbonne
- Revision 9: published
- Revision 11: published
- Revision 14: published Yuval
- Revision 15: published Ian Obermiller
- Revision 16: published ThinkingStiff
- Revision 17: published ThinkingStiff
- Revision 18: published
- Revision 20: published Prestaul
- Revision 22: published Anentropic
- Revision 23: published
- Revision 24: published
- Revision 25: published Anentropic
- Revision 26: published
- Revision 27: published
- Revision 28: published Marek
- Revision 29: published
- Revision 30: published Marek
- Revision 31: published Marek
- Revision 32: published
- Revision 33: published Mr_Green
- Revision 34: published Marek
- Revision 35: published Marek
- Revision 38: published
- Revision 39: published
- Revision 40: published
- Revision 44: published
- Revision 45: published
- Revision 46: published
- Revision 48: published
- Revision 49: published
- Revision 50: published
- Revision 52: published hoochieminh
- Revision 53: published
- Revision 56: published Eric
- Revision 59: published
- Revision 60: published Phillip Couto
- Revision 61: published
- Revision 62: published
- Revision 64: published
- Revision 65: published PW
- Revision 66: published
- Revision 67: published
- Revision 68: published
- Revision 69: published
- Revision 72: published Carl Xiong
- Revision 73: published
- Revision 74: published
- Revision 75: published
- Revision 77: published
- Revision 78: published
- Revision 79: published
- Revision 81: published D'Arcy Rittich
0 Comments