Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Lru cache
Lru clock 2 hand version
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser:
Chrome 137
Operating system:
Windows
Device Platform:
Desktop
Date tested:
10 months ago
Test name
Executions per second
Test1
13130.5 Ops/sec
Test2
142.1 Ops/sec
Tests:
Test1
let Lru = function(cacheSize,callbackBackingStoreLoad,elementLifeTimeMs=1000){ let maxWait = elementLifeTimeMs; let size = parseInt(cacheSize,10); let mapping = {}; // mapping from key to buffer index let buf = []; // actual buffer that holds cache data for(let i=0;i<size;i++) { let rnd = Math.random(); mapping[rnd] = i; buf.push({data:"",visited:false, key:rnd}); } let ctr = 0; // second-chance "hand" of clock algorithm let ctrEvict = parseInt(cacheSize/2,10); // eviction "hand" of clock alg. let loadData = callbackBackingStoreLoad; // user-given data-storage load fn. this.get = async function(key){ if(key in mapping) { // RAM speed // check lifetime is over if(Date.now() - buf[mapping[key]].time > maxWait) { delete mapping[key]; return await me.get(key); } else { // not over, load from RAM buf[mapping[key]].visited=true; buf[mapping[key]].time = Date.now(); return buf[mapping[key]].data; } } else { // load at data store speed (hdd, network, ...) // find a slot to evict for new data let ctrFound = -1; while(ctrFound===-1) { // give "another chance" to some "failed" slots if(buf[ctr].visited) { buf[ctr].visited=false; } ctr++; if(ctr >= size) { ctr=0; } // find a victim if(!(buf[ctrEvict].visited)) { // evict 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(95/* cache size*/,async function(key){ /* cache miss, load from data-store */ for(let i=0;i<10000;i++){} return key; },50 /*miliseconds before next get() invalidates data */); async function runThis() { for(let i=0;i<1000;i++) { let myData = await lru.get(parseInt(Math.random()*100,10).toString()); console.log(myData); } } runThis();
Test2
async function runThis() { for(let i=0;i<1000;i++) { for(let j=0;j<10000;j++){} console.log(parseInt(Math.random()*100,10)); } } runThis();