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
This is an implementation of strip that is meant to be used over trim for its advanced features as well as a poly-fill
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.string/3.0.2/underscore.string.min.js"></script>
var strip = function(string, characters) {
'use strict';
if(!characters) {
if(typeof String.prototype.trim !== undefined) {
// Simply use the String.trim as a default
return String.prototype.trim.call(string);
} 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 + ']+|[' + escaped + ']+$');
// Remove the characters from the beginning of the string
string = string.replace(target, '');
};
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 |
Underscore.string trimming |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.