Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lru cache 50% hit ratio test
(version: 0)
Lru clock 2 hand version
Comparing performance of:
Test1 vs Test2
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
Test1
let Lru = function(cacheSize,callbackBackingStoreLoad,elementLifeTimeMs=1000){ let maxWait = elementLifeTimeMs; let size = parseInt(cacheSize,10); let mapping = {}; let buf = []; for(let i=0;i<size;i++) { let rnd = Math.random(); mapping[rnd] = i; buf.push({data:"",visited:false, key:rnd, time:Date.now()}); } let ctr= 0; let ctrEvict= parseInt(cacheSize/2,10); let loadData = callbackBackingStoreLoad; this.get = async function(key){ if(key in mapping) { if(Date.now() - buf[mapping[key]].time > maxWait) { delete mapping[key]; return await me.get(key); } else { buf[mapping[key]].visited=true; buf[mapping[key]].time = Date.now(); return buf[mapping[key]].data; } } else { let ctrFound = -1; while(ctrFound===-1) { if(buf[ctr].visited) { buf[ctr].visited=false; } ctr++; if(ctr >= size) { ctr=0; } if(!(buf[ctrEvict].visited)) { ctrFound = ctrEvict; } ctrEvict++; if(ctrEvict >= size) { ctrEvict=0; } } delete mapping[buf[ctrFound].key]; mapping[key] = ctrFound; let dataKey = await loadData(key); buf[ctrFound] = {data:dataKey, visited:false, key:e.now()}; return buf[ctrFound].data; } }; }; let lru = new Lru(10, async function(key){ /* cache miss, load from data-store */ let wait=Date.now();let aa=0; while(Date.now()-wait<1){aa++;} return aa.toString()+key; },5000 /*miliseconds before next get() invalidates data */); let c=0; async function runThis() { c++; let myData =await lru.get(parseInt(Math.random()*100,10).toString()+"ee"); console.log(myData); if(c<1000) setImmediate(runThis) } runThis();
Test2
async function runThis() { for(let i=0;i<1000;i++) { let wait=Date.now(); while(Date.now()-wait<1){} console.log(parseInt(Math.random()*100,10)); } } runThis();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Test1
Test2
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Browser/OS:
Chrome 132 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Test1
998.3 Ops/sec
Test2
1.0 Ops/sec
Related benchmarks:
cached vs uncached math.pi
cached vs uncached math.pi (const)
branchless 4x compare vs 4x cached
toFixed vs toPrecision vs Math.round() feat. Math.pow
toFixed vs Math.round() sd6f54sd6f54
Comments
Confirm delete:
Do you really want to delete benchmark?