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
Test perf of building messages from prebuilt or build-as-you-go message object
// Mock builds
const messageBuilds = ['desktop', 'mobile'];
// Mock file paths
const mockFiles = [
'bones/en.json',
'bones/fr.json',
'bones/de.json',
'order/en.json',
'order/fr.json',
'order/de.json',
];
// Mock file contents
const mockFileContent = {
'bones/en.json':
'{"bones/postPurchaseNotification": { "desktop": { "text": "Add a year of security with an exclusive new member deal! Expires in 24 hours.", "showButton": "View deal" }, "mobile": { "text": "Newcomer deal expires in 24 hours!", "showButton": "View" }}}',
'bones/fr.json':
'{"bones/postPurchaseNotification": { "desktop": { "text": "Add a year of security with an exclusive new member deal! Expires in 24 hours.", "showButton": "View deal" }, "mobile": { "text": "Newcomer deal expires in 24 hours!", "showButton": "View" }}}',
'bones/de.json':
'{"bones/postPurchaseNotification": { "desktop": { "text": "Add a year of security with an exclusive new member deal! Expires in 24 hours.", "showButton": "View deal" }, "mobile": { "text": "Newcomer deal expires in 24 hours!", "showButton": "View" }}}',
'order/en.json':
'{"pagePurchase":{"title":"Enter the email for your Surfshark account","emailConfirmed":"Email confirmed","loggedIn":"Logged-in with","desktop":{"email":{"wontShareYourEmail":"We won’t share your email address with any third parties, and will only contact you when necessary to ensure service quality or to announce special offers.","invalidEmail":"Please enter a valid email address.","continueWith":"Or continue with"}},"choosePayment":"Choose a payment method","moneyBackGuarantee":"Money-back{br}guarantee","day":"day"}}',
'order/fr.json':
'{"pagePurchase":{"title":"Enter the email for your Surfshark account","emailConfirmed":"Email confirmed","loggedIn":"Logged-in with","desktop":{"email":{"wontShareYourEmail":"We won’t share your email address with any third parties, and will only contact you when necessary to ensure service quality or to announce special offers.","invalidEmail":"Please enter a valid email address.","continueWith":"Or continue with"}},"choosePayment":"Choose a payment method","moneyBackGuarantee":"Money-back{br}guarantee","day":"day"}}',
'order/de.json':
'{"pagePurchase":{"title":"Enter the email for your Surfshark account","emailConfirmed":"Email confirmed","loggedIn":"Logged-in with","desktop":{"email":{"wontShareYourEmail":"We won’t share your email address with any third parties, and will only contact you when necessary to ensure service quality or to announce special offers.","invalidEmail":"Please enter a valid email address.","continueWith":"Or continue with"}},"choosePayment":"Choose a payment method","moneyBackGuarantee":"Money-back{br}guarantee","day":"day"}}',
};
// Mock Helper Functions
const basename = (file, ext) => file.replace(ext, '');
const isObject = o =>
typeof o === 'object' && o !== null && !Array.isArray(o);
const appendProp = (currentProp, prop) =>
(currentProp ? `${currentProp}.${prop}` : prop);
const { entries, assign } = Object;
const flattenObject = (value, currentProp) => {
if (!isObject(value)) return { [currentProp]: value };
return entries(value).reduce(
(o, [prop, val]) => ({
...o,
...flattenObject(val, appendProp(currentProp, prop)),
}),
{},
);
};
const filterBuilds = (value, build, builds) => {
if (!isObject(value)) return value;
return entries(value).reduce((o, [key, val]) => {
if (isObject(val)) {
if (key === build) assign(o, filterBuilds(val, build, builds));
else if (!builds.includes(key))
assign(o, { [key]: filterBuilds(val, build, builds) });
} else assign(o, { [key]: val });
return o;
}, {});
};
const files = mockFiles;
const locales = [...new Set(files.map(file => basename(file, '.json')))];
const prebuiltMessagesObject = Object.fromEntries(
locales.map(locale => [
locale,
Object.fromEntries(
messageBuilds.map(build => [build, {}]),
),
]),
);
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| Old | | ready |
| New | | ready |
| New with object build included | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.