Skip to content

Commit

Permalink
Add UI feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 1, 2017
1 parent 4f8b103 commit d4a7977
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 87 deletions.
142 changes: 60 additions & 82 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,62 @@
var LRU = require('lru')
var LruCache = require('lru-cache')
var tinyLRU = require('tiny-lru')
var SecondaryCache = require('secondary-cache')
var LRU_Cache = require('lru_cache').LRUCache
var Modern = require('modern-lru')
var Simple = require('simple-lru-cache')
var Faster = require('faster-lru-cache').default
var MKC = require('mkc')
//var Lighter = require('lighter-lru-cache') //could not figure out API
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,
'lru': LRU,
'simple-lru-cache': function (n) { return new Simple({maxSize: n}) },
'mkc': function (n) { return new MKC({max: n}) },
'lru-fast': function (n) { return new Fast(n) },
'faster-lru-cache': function (n) { return new Faster(n) },
'secondary-cache': SecondaryCache
'use strict'

const {readFileSync, createWriteStream} = require('fs')
const markdownTables = require('markdown-tables')
const bench = require('./bench')
const path = require('path')
const ora = require('ora')

const LRU_Cache = require('lru_cache').LRUCache
const Simple = require('simple-lru-cache')
const Fast = require('lru-fast').LRUCache
const QuickLRU = require('quick-lru')
const Modern = require('modern-lru')
const MKC = require('mkc')

const lrus = {
'simple-lru-cache': maxSize => new Simple({maxSize}),
'secondary-cache': require('secondary-cache'),
'modern-lru': n => new Modern(n),
lru_cache: n => new LRU_Cache(n),
'lru-fast': n => new Fast(n),
mkc: n => new MKC({max: n}),
hashlru: require('hashlru'),
'lru-cache': require('lru-cache'),
'tiny-lru': require('tiny-lru'),
lru: require('lru'),
'quick-lru': maxSize => new QuickLRU({maxSize})
}

function run(LRU, N) {
var lru = LRU(N)
//set
var start = Date.now()
for(var i = 0; i < N; i++)
lru.set(i, Math.random())

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, a2, b, b2, c]
}

var N = 100000

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(', '))
}






const N = 100000
const headers = [
'name',
'set',
'get1',
'update',
'get2',
'evict'
];

const buffer = [headers.join(',')]

const keys = Object.keys(lrus)
const size = keys.length

Object.keys(lrus).forEach((lruName, index) =>{
const spinner = ora(`${lruName} ${index}/${size}`).start();

const lru = lrus[lruName]
const result = bench(lru, N)

const output = result.reduce((acc, value, index) => {
acc.push(Math.round(N / value))
return acc
}, [`[${lruName}](https://npm.im/${lruName})`])

buffer.push(output.join(','))
spinner.stop()
})


const table = markdownTables(buffer.join('\n'))
console.log(table)
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@
"bugs": {
"url": "https://github.com/dominictarr/bench-lru/issues"
},
"dependencies": {
"devDependencies": {
"faster-lru-cache": "^2.0.0",
"hashlru": "^1.0.3",
"lighter-lru-cache": "^1.0.0",
"lru": "^3.1.0",
"lru-cache": "^4.0.1",
"lru-fast": "^0.2.2",
"lru-native": "^0.4.0",
"lru_cache": "^1.0.2",
"lrucache": "^1.0.2",
"markdown-tables": "~1.1.4",
"mkc": "^1.3.0",
"modern-lru": "^1.0.8",
"nan": "^2.5.0",
"ora": "~1.3.0",
"quick-lru": "~1.1.0",
"secondary-cache": "^1.2.1",
"simple-lru-cache": "0.0.2",
"tiny-lru": "^1.4.1",
"tiny-lru-cache": "^1.0.1"
},
"devDependencies": {},
"scripts": {
"test": "node index.js"
},
Expand Down

0 comments on commit d4a7977

Please sign in to comment.