diff --git a/bench.js b/bench.js new file mode 100644 index 0000000..88f42b5 --- /dev/null +++ b/bench.js @@ -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 + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 1f0828f..05ff5ff 100644 --- a/package.json +++ b/package.json @@ -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": "dominic.tarr@gmail.com", + "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", @@ -29,6 +38,5 @@ "scripts": { "test": "node index.js" }, - "author": "'Dominic Tarr' (dominictarr.com)", "license": "MIT" }