Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
memo vs no memo multiple
(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(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 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(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 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(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 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):
The benchmark results show the performance difference between two test cases: `memo - big strings` and `no memo - big strings`. Here's what we can infer from these results: 1. **Memoization**: The `memo - big strings` test case shows an average execution rate of 109 executions per second, while the `no memo - big strings` test case has an average execution rate of 106.97 executions per second. This suggests that memoization improves performance by approximately 2% for large inputs. 2. **Memoization with few inputs**: The `memo - many strings` test case shows an average execution rate of 113.24 executions per second, while the `no memo - many strings` test case has an average execution rate of 112.66 executions per second. This suggests that memoization improves performance by approximately 1% for small to moderate inputs. 3. **No memoization**: The `no memo - few strings` and `no memo - big strings` test cases have similar execution rates, which indicates that without memoization, there is little room for optimization in these scenarios. 4. **Memoization with a small number of unique inputs**: The `memo - many strings` test case shows better performance than the `no memo - many strings` test case, suggesting that memoization can provide benefits even when dealing with large numbers of unique inputs. 5. **Other factors affecting performance**: It's worth noting that other factors such as browser, device platform, operating system, and random variations in input may have affected the execution rates observed in these tests.
Related benchmarks:
Javascript 'concat()' vs '+' for strings
.join vs string builder vs string concatenation
String concatenation vs concat method
Javascript 'concat()' vs '+'
lodash merge vs deepmerge vs deepmerge-ts vs @fastify/deepmerge vs just-extend (take 3)
Comments
Confirm delete:
Do you really want to delete benchmark?