jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
revertHtmlEntities
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>function revertHtmlEntities(str) {
return String(str)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"');
}
function basePropertyOf(object) {
return function(key) {
return object == null ? undefined : object[key];
};
}
var htmlUnescapes = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
''': "'"
};
var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
reUnescapedHtml = /[&<>"']/g,
reHasEscapedHtml = RegExp(reEscapedHtml.source),
reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
function revertHtmlEntities2(str) {
const string = String(str);
return (string && reHasEscapedHtml.test(string))
? string.replace(reEscapedHtml, unescapeHtmlChar)
: string;
}
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| lodash/unescape | | ready |
| revertHtmlEntities | | ready |
| lodash/unescape (noop) | | ready |
| revertHtmlEntities (noop) | | ready |
| revertHtmlEntities2 | | ready |
| revertHtmlEntities2 (noop) | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.