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
Only test the .text/.textFast methods not the jQuery selector engine
<script src="https://code.jquery.com/jquery.js"></script>
<div>
<h3>cool.</h3>
<!-- comment -->
text node
<div>
<div>inception</div>
</div>
</div>
<script>
var div = jQuery("div:first");
jQuery.fn.textFast = function(text) {
if (jQuery.isFunction(text)) {
return this.each(function(i) {
var self = jQuery(this);
self.text(text.call(this, i, self.text()));
});
}
if (typeof text !== "object" && text !== undefined) {
return this.empty().append((this[0] && this[0].ownerDocument || document).createTextNode(text));
}
return jQuery.textFast(this);
}
jQuery.textFast = function(elems) {
var ret = "",
elem;
for (var i = 0; elems[i]; i++) {
elem = elems[i];
// thie part is new.
ret += elem.textContent || elem.innerText || Sizzle.getText(elem.childNodes);
}
return ret;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Regular jQuery.text() |
| ready |
Optimized text() |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.