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
var strip = function(string, characters) {
if(!characters) {
if(typeof String.prototype.trim !== undefined) {
// Simply use the String.trim as a default
return string.trim();
} else {
// set characters to whitespaces
characters = "\s\uFEFF\xA0";
}
}
// Characters is set at this point forward
// Validate characters just in case there are invalid usages
var escaped = characters.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
var target = new RegExp('['+ escaped +']+');
var targetBeginning = new RegExp('^[' + escaped + ']+');
// Remove the characters from the beginning of the string
string = string.replace(targetBeginning, '');
var i = string.length;
// Remove the characters from the end of the string
while (target.test(string.charAt(--i)));
return string.slice(0, i + 1);
};
Ready to run.
Test | Ops/sec | |
---|---|---|
Trimming with trim |
| ready |
Trimming with strip |
| ready |
Trimming with many spaces |
| ready |
Stripping with many spaces |
| ready |
Stripping characters |
| ready |
Stripping multiple chars |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.