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
Testing to confirm the fastest way to pop the tld off a hostname. My hunch is that lastIndexOf() is faster, as opposed to the often seen split('.').pop().
split('.') causes an array to be create, meaning memory alloc/dealloc, etc. I expect split('.') to be slower.
function tld_split(hostname) {
return hostname.split('.').pop();
}
function tld_lastIndexOf(hostname) {
var pos = hostname.lastIndexOf('.');
if (pos < 0) {
return hostname;
}
return hostname.slice(pos + 1);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
tld_split |
| ready |
tld_lastIndexOf |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.