Skip to content

Commit

Permalink
use hashlru, and benchmark reads also
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed Dec 23, 2016
1 parent f566cd2 commit 6fea600
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ var Fast = require('lru-fast').LRUCache
var Native = require('lru-native')

var algs = {
'hashlru': require('hashlru'),
'lru-native': Native,
'modern-lru': function (n) { return new Modern(n) },
'lru-cache': LruCache,
'lru_cache': function (n) { return new LRU_Cache(n) },
'tiny-lru': tinyLRU,
// 'tiny-lru': tinyLRU,
'lru': LRU,
'simple-lru-cache': function (n) { return new Simple({maxSize: n}) },
'mkc': function (n) { return new MKC({max: n}) },
Expand All @@ -34,31 +35,50 @@ function run(LRU, N) {

var a = Date.now() - start


var start_2 = Date.now()
for(var i = 0; i < N; i++) lru.get(i)

var a2 = Date.now() - start_2


//update
var start2 = Date.now()
for(var i = 0; i < N; i++)
lru.set(i, Math.random())

var b = Date.now() - start2


var start_3 = Date.now()
for(var i = 0; i < N; i++) lru.get(i)

var b2 = Date.now() - start_3


// if(lru.newCache) lru.newCache()

//evict
var start3 = Date.now(), M = N*2
for(var i = N; i < M; i++)
lru.set(i, Math.random())

var c = Date.now() - start3

return [a, b, c]
return [a, a2, b, b2, c]
}



var N = 100000

console.log('name, set, update, evict')
console.log('name, set, get1, update, get2, evict')

for(var name in algs) {
var v = run(algs[name], N).map(function (e) { return Math.round(N/(e)) })
console.log([name].concat(v).join(', '))
}






0 comments on commit 6fea600

Please sign in to comment.