Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
refactor 3 iterations vs 1 iteration
(version: 1)
Comparing performance of:
original 3 iterations vs improved 1 iteration
Created:
one month ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
function randomHash() { return Math.random().toString(36).substring(2, 12); } function generateDataset(size) { const contactsToSync = []; const syncedContacts = []; const phoneHashes = []; const emailHashes = []; for (let i = 0; i < size; i++) { const phoneHash = randomHash(); const emailHash = randomHash(); phoneHashes.push(phoneHash); emailHashes.push(emailHash); contactsToSync.push({ name: "Contact " + i, phoneNumberHashed: phoneHash, emailAddressHashed: emailHash, }); } for (let i = 0; i < size; i++) { const usePhone = Math.random() > 0.5; syncedContacts.push({ matched_by: { phone_hash: usePhone ? phoneHashes[Math.floor(Math.random() * size)] : undefined, email_hash: !usePhone ? emailHashes[Math.floor(Math.random() * size)] : undefined, }, contact: { paytag: "user_" + i, }, }); } return { contactsToSync, syncedContacts }; } var { contactsToSync, syncedContacts } = generateDataset(20000);
Tests:
original 3 iterations
/*When writing async/deferred tests, use `deferred.resolve()` to mark test as done*/ let matchedPhoneNumberHashes = []; let matchedEmailAddressHashes = []; let paytagToContactBookNameMap = {}; matchedPhoneNumberHashes = syncedContacts .map((contact) => contact.matched_by.phone_hash) .filter((item) => !!item); matchedEmailAddressHashes = syncedContacts .map((contact) => contact.matched_by.email_hash) .filter((item) => !!item); syncedContacts.forEach((syncedContact) => { const contactBookName = contactsToSync.find( (contact) => contact.phoneNumberHashed === syncedContact.matched_by.phone_hash || contact.emailAddressHashed === syncedContact.matched_by.email_hash, )?.name; if (contactBookName) { paytagToContactBookNameMap[syncedContact.contact.paytag] = contactBookName; } });
improved 1 iteration
let matchedPhoneNumberHashes = []; let matchedEmailAddressHashes = []; let paytagToContactBookNameMap = {}; // Build fast lookup tables once let phoneHashToName = new Map(); let emailHashToName = new Map(); for (const contact of contactsToSync) { if (contact.phoneNumberHashed && !phoneHashToName.has(contact.phoneNumberHashed)) { phoneHashToName.set(contact.phoneNumberHashed, contact.name); } if (contact.emailAddressHashed && !emailHashToName.has(contact.emailAddressHashed)) { emailHashToName.set(contact.emailAddressHashed, contact.name); } } // Single pass over syncedContacts for (const syncedContact of syncedContacts) { const phoneHash = syncedContact.matched_by.phone_hash; const emailHash = syncedContact.matched_by.email_hash; if (phoneHash) matchedPhoneNumberHashes.push(phoneHash); if (emailHash) matchedEmailAddressHashes.push(emailHash); const contactBookName = (phoneHash ? phoneHashToName.get(phoneHash) : undefined) ?? (emailHash ? emailHashToName.get(emailHash) : undefined); if (contactBookName) { paytagToContactBookNameMap[syncedContact.contact.paytag] = contactBookName; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
original 3 iterations
improved 1 iteration
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Browser/OS:
Chrome 145 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
original 3 iterations
1.3 Ops/sec
improved 1 iteration
432.6 Ops/sec
Related benchmarks:
map vs forEach schnelligkeit
JS insert at index spread vs Splice
fdgfd ergfdg gergtdg
String concatenation vs element creation 2
Map vs Find to change one el in array of objects
Array timing 100
100 array
run multiple iterations vs 1 iteration
multiple iteration vs single iteration diff size
Comments
Confirm delete:
Do you really want to delete benchmark?