Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
memo vs no memo multiple inverted
(version: 0)
Checking if concatenating two strings is costly enough to need memoization
Comparing performance of:
No memo - few strings vs Memo - few strings vs no memo - many strings vs memo - many strings vs no memo - big strings vs memo - big strings
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
No memo - few strings
const memoizationTwoArgs = ( func ) => { const cache = {}; function memoFunc(a, b) { if (!cache.hasOwnProperty(a)) { cache[a] = {}; } if (!cache[a].hasOwnProperty(b)) { cache[a][b] = func(a, b); } return cache[a][b]; } return memoFunc; }; const randStringGen = (len) => Math.random().toString(16).substr(2, 2+len); const randIntGen = (min, max) => parseInt((Math.random() * (max - min + 1)), 10) + min; const partIds = []; for (let i=0;i<5;i++) { partIds.push(randStringGen(20)); } const meetingIds = []; for (let i=0;i<2;i++) { meetingIds.push(randStringGen(20)); } const func = (a,b) => `${a}/${b}`; for (let i=0;i<1000;i++) { const a = partIds[randIntGen(0, partIds.length-1)]; const b = meetingIds[randIntGen(0, meetingIds.length-1)]; console.log(func(a,b)); }
Memo - few strings
const memoizationTwoArgs = ( func ) => { const cache = {}; function memoFunc(a, b) { if (!cache.hasOwnProperty(b)) { cache[b] = {}; } if (!cache[b].hasOwnProperty(a)) { cache[b][a] = func(a, b); } return cache[b][a]; } return memoFunc; }; const randStringGen = (len) => Math.random().toString(16).substr(2, 2+len); const randIntGen = (min, max) => parseInt((Math.random() * (max - min + 1)), 10) + min; const partIds = []; for (let i=0;i<5;i++) { partIds.push(randStringGen(20)); } const meetingIds = []; for (let i=0;i<2;i++) { meetingIds.push(randStringGen(20)); } const memoFunc = memoizationTwoArgs((a,b) => `${a}/${b}`); for (let i=0;i<1000;i++) { const a = partIds[randIntGen(0, partIds.length-1)]; const b = meetingIds[randIntGen(0, meetingIds.length-1)]; console.log(memoFunc(a,b)); }
no memo - many strings
const memoizationTwoArgs = ( func ) => { const cache = {}; function memoFunc(a, b) { if (!cache.hasOwnProperty(a)) { cache[a] = {}; } if (!cache[a].hasOwnProperty(b)) { cache[a][b] = func(a, b); } return cache[a][b]; } return memoFunc; }; const randStringGen = (len) => Math.random().toString(16).substr(2, 2+len); const randIntGen = (min, max) => parseInt((Math.random() * (max - min + 1)), 10) + min; const partIds = []; for (let i=0;i<100;i++) { partIds.push(randStringGen(20)); } const meetingIds = []; for (let i=0;i<2;i++) { meetingIds.push(randStringGen(20)); } const func = (a,b) => `${a}/${b}`; for (let i=0;i<1000;i++) { const a = partIds[randIntGen(0, partIds.length-1)]; const b = meetingIds[randIntGen(0, meetingIds.length-1)]; console.log(func(a,b)); }
memo - many strings
const memoizationTwoArgs = ( func ) => { const cache = {}; function memoFunc(a, b) { if (!cache.hasOwnProperty(b)) { cache[b] = {}; } if (!cache[b].hasOwnProperty(a)) { cache[b][a] = func(a, b); } return cache[b][a]; } return memoFunc; }; const randStringGen = (len) => Math.random().toString(16).substr(2, 2+len); const randIntGen = (min, max) => parseInt((Math.random() * (max - min + 1)), 10) + min; const partIds = []; for (let i=0;i<100;i++) { partIds.push(randStringGen(20)); } const meetingIds = []; for (let i=0;i<2;i++) { meetingIds.push(randStringGen(20)); } const memoFunc = memoizationTwoArgs((a,b) => `${a}/${b}`); for (let i=0;i<1000;i++) { const a = partIds[randIntGen(0, partIds.length-1)]; const b = meetingIds[randIntGen(0, meetingIds.length-1)]; console.log(memoFunc(a,b)); }
no memo - big strings
const memoizationTwoArgs = ( func ) => { const cache = {}; function memoFunc(a, b) { if (!cache.hasOwnProperty(a)) { cache[a] = {}; } if (!cache[a].hasOwnProperty(b)) { cache[a][b] = func(a, b); } return cache[a][b]; } return memoFunc; }; const randStringGen = (len) => Math.random().toString(16).substr(2, 2+len); const randIntGen = (min, max) => parseInt((Math.random() * (max - min + 1)), 10) + min; const partIds = []; for (let i=0;i<5;i++) { partIds.push(randStringGen(100)); } const meetingIds = []; for (let i=0;i<2;i++) { meetingIds.push(randStringGen(100)); } const func = (a,b) => `${a}/${b}`; for (let i=0;i<1000;i++) { const a = partIds[randIntGen(0, partIds.length-1)]; const b = meetingIds[randIntGen(0, meetingIds.length-1)]; console.log(func(a,b)); }
memo - big strings
const memoizationTwoArgs = ( func ) => { const cache = {}; function memoFunc(a, b) { if (!cache.hasOwnProperty(b)) { cache[b] = {}; } if (!cache[b].hasOwnProperty(a)) { cache[b][a] = func(a, b); } return cache[b][a]; } return memoFunc; }; const randStringGen = (len) => Math.random().toString(16).substr(2, 2+len); const randIntGen = (min, max) => parseInt((Math.random() * (max - min + 1)), 10) + min; const partIds = []; for (let i=0;i<5;i++) { partIds.push(randStringGen(100)); } const meetingIds = []; for (let i=0;i<2;i++) { meetingIds.push(randStringGen(100)); } const memoFunc = memoizationTwoArgs((a,b) => `${a}/${b}`); for (let i=0;i<1000;i++) { const a = partIds[randIntGen(0, partIds.length-1)]; const b = meetingIds[randIntGen(0, meetingIds.length-1)]; console.log(memoFunc(a,b)); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
No memo - few strings
Memo - few strings
no memo - many strings
memo - many strings
no memo - big strings
memo - big strings
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
A benchmarking result! To analyze this result, I'll focus on the test names and their corresponding execution rates. **Test Names:** 1. **"no memo - few strings"**: This test likely checks the execution speed of a function without memoization when dealing with small strings. 2. **"Memo - few strings"**: This test likely checks the execution speed of a function with memoization when dealing with small strings. 3. **"no memo - many strings"**: This test likely checks the execution speed of a function without memoization when dealing with large numbers of strings. 4. **"memo - many strings"**: This test likely checks the execution speed of a function with memoization when dealing with large numbers of strings. 5. **"no memo - big strings"**: This test likely checks the execution speed of a function without memoization when dealing with very large strings. 6. **"memo - big strings"**: This test likely checks the execution speed of a function with memoization when dealing with very large strings. **Benchmark Results:** The results show that: * Without memoization (`"no memo - few strings"`, `"no memo - many strings"`, and `"no memo - big strings"`), the execution rates are: + Low for small strings (`108.34` executions per second) + Moderate for large numbers of small strings (`70.15` executions per second) + Very low for very large strings (`65.46` executions per second) * With memoization (`"Memo - few strings"` and `"memo - many strings"`), the execution rates are: + Higher than without memoization for small strings (`110.91` executions per second, but still lower than `108.34`) + Similar to or slightly higher than without memoization for large numbers of small strings (`67.79` executions per second) * The results for `"memo - big strings"` and `"no memo - big strings"` are close in terms of execution rates (`65.46` and `65.46`, respectively), suggesting that memoization has a minimal impact on performance when dealing with very large strings. **Conclusion:** Memoization seems to have a positive effect on performance for small and moderate-sized inputs, but not significantly so for very large inputs. This is consistent with the expected behavior of memoization, which can reduce the number of redundant calculations required for smaller inputs, but may not be able to overcome the limitations imposed by algorithmic complexity or memory constraints when dealing with extremely large datasets.
Related benchmarks:
slice vs substr vs substring (with end index & large string)
slice vs substring (long string)
Array from vs string split with large strings
String.prototype.split vs String.prototype.match for word count
IndexOf vs Includes in string - larger string edition
Comments
Confirm delete:
Do you really want to delete benchmark?