-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verbose statements, fixing
remove()
by moving a notify()
into a c…
…onditional statement when a key is valid, adding `benchmark.js` for dev purposes
- Loading branch information
Showing
8 changed files
with
87 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
.eslintrc | ||
.travis.yml | ||
Gruntfile.js | ||
benchmark.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const path = require("path"), | ||
lru = require(path.join(__dirname, "lib", "tiny-lru.js")), | ||
precise = require("precise"), | ||
nth = 2e5, | ||
cache = lru(nth), | ||
data = new Array(nth); | ||
|
||
function seed () { | ||
let i = -1; | ||
|
||
while (++i < nth) { | ||
data[i] = Math.floor(Math.random() * nth); | ||
} | ||
} | ||
|
||
function populate (arg, start = 0) { | ||
const nth = arg.max; | ||
let i = -1; | ||
|
||
while (++i < nth) { | ||
arg.set(i + start, data[i]); | ||
} | ||
} | ||
|
||
function bench (n = 0, x = 1) { | ||
seed(); | ||
|
||
const timer = precise().start(); | ||
|
||
populate(cache, n); | ||
timer.stop(); | ||
console.log(`Run ${x} ${x === 1 ? "Set" : "Evict"} (${n === 0 ? "Low Keys" : "High Keys"}): ${timer.diff() / 1e6} ms`); | ||
} | ||
|
||
console.log(`Benchmarking ${nth} items (random value per run)`); | ||
bench(); | ||
bench(nth, 2); | ||
bench(void 0, 3); | ||
bench(nth, 4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters