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
function mymap(xs, f) {
const r = [];
for (let i = 0; i < xs.length; i++) {
r.push(f(xs[i]));
}
return r;
}
function myflatmap(xs, f) {
const r = [];
for (let i = 0; i < xs.length; i++) {
r.push(... f(xs[i]));
}
return r;
}
function maponly(s) {
return s.split(/[^a-z0-9]+/i).map(_ => _[0].toUpperCase() + _.slice(1)).join('');
}
function filterish(s) {
return s.split(/[^a-z0-9]+/i).filter(Boolean).map(_ => _[0].toUpperCase() + _.slice(1)).join('');
}
function flatmapish(s) {
return s.split(/[^a-z0-9]+/i).flatMap(_ => _ ? [_[0].toUpperCase() + _.slice(1)] : []).join('');
}
function quasifiltermapish(s) {
return s.split(/[^a-z0-9]+/i).flatMap(_ => _ ? _[0].toUpperCase() + _.slice(1) : []).join('');
}
function skel_filterish(s) {
return s.split(/[^a-z0-9]+/i).filter(Boolean).map(_ => 'a').join('');
}
function skel_maponly(s) {
return s.split(/[^a-z0-9]+/i).map(_ => 'a').join('');
}
function skel_flatmapish(s) {
return s.split(/[^a-z0-9]+/i).flatMap(_ => 'a').join('');
}
function my_filterish(s) {
return mymap(s.split(/[^a-z0-9]+/i).filter(Boolean), _ => _[0].toUpperCase() + _.slice(1)).join('');
}
function my_flatmapish(s) {
return myflatmap(s.split(/[^a-z0-9]+/i), _ => _ ? [_[0].toUpperCase() + _.slice(1)] : []).join('');
}
function direct(s) {
const pieces = s.split(/[^a-z0-9]+/i);
const r = [];
for (let i = 0; i < pieces.length; i++) {
const _ = pieces[i];
if (_) {
r.push(_[0].toUpperCase() + _.slice(1));
}
}
return r.join('');
}
function direct2(s) {
if (!s) return '';
const pieces = s.split(/[^a-z0-9]+/i);
const r = [];
for (let i = 0; i < pieces.length; i++) {
const _ = pieces[i];
r.push(_[0].toUpperCase() + _.slice(1));
}
return r.join('');
}
function direct_flatmap(s) {
const pieces = s.split(/[^a-z0-9]+/i);
const r = [];
for (let i = 0; i < pieces.length; i++) {
const _ = pieces[i];
if (_) {
const rs = [_[0].toUpperCase() + _.slice(1)];
r.push(... rs);
}
}
return r.join('');
}
function direct_flatmap2(s) {
const pieces = s.split(/[^a-z0-9]+/i);
const r = [];
for (let i = 0; i < pieces.length; i++) {
const _ = pieces[i];
const rs = _ ? [_[0].toUpperCase() + _.slice(1)] : [];
r.push(... rs);
}
return r.join('');
}
function direct_flatmap3(s) {
const pieces = s.split(/[^a-z0-9]+/i);
const r = [];
for (let i = 0; i < pieces.length; i++) {
const _ = pieces[i];
if (_) {
const rs = [_[0].toUpperCase() + _.slice(1)];
r.push(... rs);
} else {
const rs = [];
r.push(... rs);
}
}
return r.join('');
}
function specialcase(s) {
return s && s.split(/[^a-z0-9]+/i).map(_ => _[0].toUpperCase() + _.slice(1)).join('');
}
Ready to run.
Test | Ops/sec | |
---|---|---|
flatmap |
| ready |
filterish |
| ready |
quasifiltermapish |
| ready |
skel_filterish |
| ready |
skel_flatmapish |
| ready |
maponly |
| ready |
skel_maponly |
| ready |
my_filterish |
| ready |
my_flatmapish |
| ready |
direct |
| ready |
direct_flatmap |
| ready |
direct_flatmap2 |
| ready |
specialcase |
| ready |
direct_flatmap3 |
| ready |
direct2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.