Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lru cache non-async version: time complexity of cache-hits
(version: 0)
Lru clock 2 hand version
Comparing performance of:
Test1 vs Test2 vs Test3
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
"use strict"; let Lru = function(cacheSize,callbackBackingStoreLoad,elementLifeTimeMs=1000){ let me=this; 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 = function(key){ if(key in mapping) { if(Date.now() - buf[mapping[key]].time > maxWait) { delete mapping[key]; return 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 = loadData(key); buf[ctrFound] = {data:dataKey, visited:false, key:key,time:Date.now()}; return buf[ctrFound].data; } }; }; document.lru = new Lru(100,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 */); document.lru2 = new Lru(1000,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 */); document.lru3 = new Lru(10000,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 */);
Tests:
Test1
let c=0; let tt=Date.now(); function runThis() { for(let i=0;i<10000;i++) { let myData = document.lru.get(parseInt(Math.random()*100,10).toString()+"ee"); console.log(myData); } } runThis();
Test2
let c=0; let tt=Date.now(); function runThis() { for(let i=0;i<10000;i++) { let myData = document.lru2.get(parseInt(Math.random()*100,10).toString()+"ee"); console.log(myData); } } runThis();
Test3
let c=0; let tt=Date.now(); function runThis() { for(let i=0;i<10000;i++) { let myData = document.lru3.get(parseInt(Math.random()*100,10).toString()+"ee"); console.log(myData); } } runThis();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Test1
Test2
Test3
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
gemma2:9b
, generated one year ago):
The provided information describes a benchmark testing the performance of three different Least Recently Used (LRU) cache implementations. Here's a breakdown: * **JavaScript Code:** The first block represents JavaScript code implementing an LRU cache (`document.lru`, `document.lru2`, `document.lru3`). Each implementation likely has its own logic for storing and retrieving data based on the recency of access. * **Benchmark Definition:** The second part outlines test cases (Test1, Test2, Test3). Each case involves: - Initializing a counter (`c`) and timestamp (`tt`). - Defining a function `runThis()` that simulates accessing data from each cache instance 10,000 times using randomly generated keys. - Logging the retrieved data (likely to verify successful retrieval) within the loop. - Executing `runThis()`. * **Latest Benchmark Result:** The final section presents benchmark results obtained under a specific environment: - **Browser & Device:** Chrome 89 on Windows Desktop. - **Executions per Second (EPS):** Measures how many times each test case could retrieve data within a second. **Insights:** * You can compare the EPS values across the three implementations to see which one performs better in terms of retrieving data from the cache. * Higher EPS generally indicates faster performance. Let me know if you have any more specific questions about the code, benchmark methodology, or the results!
Related benchmarks:
Lru cache
Lru cache 50% hit ratio test
Lru cache non-async version with 99 percent hit ratio
Lru cache non-async version: time complexity of cache-miss
Comments
Confirm delete:
Do you really want to delete benchmark?