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
const rawParams = {
country_code: 'US',
city: 'New York',
postal_code: '10001',
region_code: 'NY',
other_key: 'Some Value',
null_key: null
};
function hashString({ rawString, algorithm }) {
return new Promise((resolve) => {
setTimeout(() => resolve(`${algorithm}_${rawString}`), Math.random() * 100);
});
}
async function processParamsWithPromiseAll(params) {
return Promise.all(
Object.entries(params).map(async ([key, value]) => {
if (key === 'country_code' && typeof value === 'string') {
return ['country', await hashString({ rawString: value.trim().toLowerCase(), algorithm: 'sha256' })];
}
if (key === 'city' && typeof value === 'string') {
return ['ct', await hashString({ rawString: value.trim().toLowerCase().replace(/\s+/g, ''), algorithm: 'sha256' })];
}
if (key === 'postal_code' && typeof value === 'string') {
return ['zp', await hashString({ rawString: value.trim().toLowerCase(), algorithm: 'sha256' })];
}
if (key === 'region_code' && typeof value === 'string') {
return ['st', await hashString({ rawString: value.trim().toLowerCase().replace(/\s+/g, ''), algorithm: 'sha256' })];
}
if (value != null) return [key, value];
return [key, null];
})
);
}
async function processParamsWithPromiseAllnoAwait(params) {
return Promise.all(
Object.entries(params).map(([key, value]) => {
if (key === 'country_code' && typeof value === 'string') {
return ['country', hashString({ rawString: value.trim().toLowerCase(), algorithm: 'sha256' })];
}
if (key === 'city' && typeof value === 'string') {
return ['ct', hashString({ rawString: value.trim().toLowerCase().replace(/\s+/g, ''), algorithm: 'sha256' })];
}
if (key === 'postal_code' && typeof value === 'string') {
return ['zp', hashString({ rawString: value.trim().toLowerCase(), algorithm: 'sha256' })];
}
if (key === 'region_code' && typeof value === 'string') {
return ['st', hashString({ rawString: value.trim().toLowerCase().replace(/\s+/g, ''), algorithm: 'sha256' })];
}
if (value != null) return [key, value];
return [key, null];
})
);
}
async function processParamsSequential(params) {
const out = [];
for (const [key, value] of Object.entries(params)) {
if (key === 'country_code' && typeof value === 'string') {
out.push(['country', await hashString({ rawString: value.trim().toLowerCase(), algorithm: 'sha256' })]);
} else if (key === 'city' && typeof value === 'string') {
out.push(['ct', await hashString({ rawString: value.trim().toLowerCase().replace(/\s+/g, ''), algorithm: 'sha256' })]);
} else if (key === 'postal_code' && typeof value === 'string') {
out.push(['zp', await hashString({ rawString: value.trim().toLowerCase(), algorithm: 'sha256' })]);
} else if (key === 'region_code' && typeof value === 'string') {
out.push(['st', await hashString({ rawString: value.trim().toLowerCase().replace(/\s+/g, ''), algorithm: 'sha256' })]);
} else if (value != null) {
out.push([key, value]);
} else {
out.push([key, null]);
}
}
return out;
}
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| Promise.all with await on hashString | | ready |
| Promise.all no await on hashString | | ready |
| no Promise.all just await on hashString | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.