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
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.9.3/lodash.js"></script>
a = ["test"];
for (var i = 0; i < 10000; i++) {
a.push("some Other Stuff");
}
s = a.join();
String.prototype.startsWithSubstring = function (pattern) {
return pattern != null && this.length >= pattern.length && this.substring(0, pattern.length) === pattern;
}
String.prototype.startsWithSlice = function (pattern) {
return pattern != null && this.length >= pattern.length && this.slice(0, pattern.length) === pattern;
}
String.prototype.startsWithSlice2 = function (pattern) {
return pattern !== undefined && pattern !== null && this.length >= pattern.length && this.slice(0, pattern.length) === pattern;
}
String.prototype.startsWithIndexOf = function (searchString, position) {
position = position || 0;
return this.indexOf(searchString, position) === position;
}
String.prototype.startsWithCharAt = function (pattern) {
if (pattern === undefined || pattern === null) return false;
var length = pattern.length;
for (var i = 0; i < length; i++) {
if (pattern.charAt(i) !== this.charAt(i)) return false;
}
return true;
}
String.prototype.startsWithCharCodeAt = function (pattern) {
if (pattern === undefined || pattern === null) return false;
var length = pattern.length;
for (var i = 0; i < length; i++) {
if (pattern.charCodeAt(i) !== this.charCodeAt(i)) return false;
}
return true;
}
function lodashlike(string, target, position) {
string = string == null ? '' : (string + '' );
position = position == null
? 0
: Math.min(position < 0 ? 0 : (+position || 0), string.length);
return string.lastIndexOf(target, position) == position;
}
function lodashlike2(string, target, position) {
if (string == null) {
string = '';
} else if (typeof string != 'string') {
string = string + '';
}
position = position == null
? 0
: Math.min(position < 0 ? 0 : (+position || 0), string.length);
return string.lastIndexOf(target, position) == position;
}
function lodashlikenostringvalidation(string, target, position) {
position = position == null
? 0
: Math.min(position < 0 ? 0 : (+position || 0), string.length);
return string.lastIndexOf(target, position) == position;
}
// Simple and predictable means fast and optimizable.
function startsWithLoop(haystack, needle, position) {
position = position == null
? 0
: Math.min(position < 0 ? 0 : (+position || 0), string.length);
var ceil = needle.length;
for(var i = position; i < ceil; i++) {
if(haystack[i] != needle[i]) return false;
}
return true;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
startsWith Loop |
| ready |
lastIndexOf |
| ready |
substring |
| ready |
slice |
| ready |
startsWithIndexOf |
| ready |
startsWithCharAt |
| ready |
startsWithCharCodeAt |
| ready |
startsWithSubstring |
| ready |
startsWith (Browser ES6) |
| ready |
startsWithSlice |
| ready |
startsWithSlice2 |
| ready |
Lodash startsWith |
| ready |
Lodash startsWith 0 |
| ready |
lodashlike |
| ready |
lodashlikenostringvalidation |
| ready |
lodashlike2 |
| ready |
indexOf |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.