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
Using indexOf to determine whether a string starts or ends with another string is not going to work well.
<script>
String.prototype.StartsWith = function(needle) {
var len = needle.length;
if (len > this.length) return false;
for (var i = 0; i < len; i++) {
if (needle.charCodeAt(i) !== this.charCodeAt(i)) return false;
}
return true;
}
String.prototype.EndsWith = function(needle) {
var len = needle.length;
if (len > this.length) return false;
var offset = this.length - len;
for (var i = 0; i < len; i++) {
if (needle.charCodeAt(i) !== this.charCodeAt(offset + i)) return false;
}
return true;
}
var hayStack = "Now is the time for all good men to come to the aid of the party";
hayStack += hayStack; // 128
hayStack += hayStack; // 256
hayStack += hayStack; // 512
hayStack += hayStack; // 1024
hayStack += hayStack; // 2048
hayStack += hayStack; // 4096
hayStack += hayStack; // 8192
hayStack += hayStack; // 16384
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Using indexOf |
| ready |
Using StartsWith |
| ready |
Using regexp |
| ready |
Using lastIndexOf |
| ready |
Using EndsWith |
| ready |
Last index using regexp no cache |
| ready |
Last index using regexp with caching |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.