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
Test the performance of different methods to get the first child in jquery
<div id="test">
<span>first</span>
<span>second</span>
<span>....</span>
<span>....</span>
<span>....</span>
<span>....</span>
<span>....</span>
<span>....</span>
<span>....</span>
<span>....</span>
<span>....</span>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
function assertEq(expected, actual) {
if (expected !== actual) {
throw new Error('Expected "' + expected + '" but found "' + actual + '"');
}
}
function isValid(el) {
assertEq('first', el.text());
}
(function($) {
$.fn.down = function() {
return $(this[0] && this[0].children && this[0].children[0]);
};
})(jQuery);
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
children().first(); |
| ready |
children(':eq(0)'); |
| ready |
down |
| ready |
children(':first'); |
| ready |
*:first |
| ready |
children().eq(0); |
| ready |
find(':first'); |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.