Skip to content

Commit

Permalink
Add bench specification
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 1, 2017
1 parent 46eead9 commit c55b726
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
45 changes: 45 additions & 0 deletions bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

const createTimestamp = () => {
const start = Date.now()
return () => Date.now() - start
}

module.exports = (lru, num = 1000) => {
const lru = createLRU(num)

//set
let setTimestamp = createTimestamp()
for(const i = 0; i < num; i++) lru.set(i, Math.random())
setTimestamp = setTimestamp()

// get
let getTimestamp = createTimestamp()
for(const i = 0; i < num; i++) lru.get(i)
let getTimestamp = getTimestamp

//update
let updateTimestmap = createTimestamp()
for(const i = 0; i < num; i++) lru.set(i, Math.random())
updateTimestmap = createTimestamp()

// get
let getTimestampTwo = createTimestamp()
for(const i = 0; i < num; i++) lru.get(i)
getTimestampTwo = createTimestamp()


//evict
let evictTimestamp = createTimestamp()
const evicts = num*2
for(const i = num; i < evicts; i++) lru.set(i, Math.random())
evictTimestamp = createTimestamp()

return [
setTimestamp,
getTimestamp,
updateTimestmap,
getTimestampTwo,
evictTimestamp
]
}
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{
"name": "bench-lru",
"description": "",
"version": "1.0.1",
"homepage": "https://github.com/dominictarr/bench-lru",
"version": "1.0.1",
"main": "index.js",
"author": {
"email": "[email protected]",
"name": "'Dominic Tarr'",
"url": "dominictarr.com"
},
"repository": {
"type": "git",
"url": "git://github.com/dominictarr/bench-lru.git"
},
"bugs": {
"url": "https://github.com/dominictarr/bench-lru/issues"
},
"dependencies": {
"faster-lru-cache": "^2.0.0",
"hashlru": "^1.0.3",
Expand All @@ -29,6 +38,5 @@
"scripts": {
"test": "node index.js"
},
"author": "'Dominic Tarr' <[email protected]> (dominictarr.com)",
"license": "MIT"
}

0 comments on commit c55b726

Please sign in to comment.