Skip to content

Commit

Permalink
Updating benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Jan 22, 2019
1 parent 5c5d9de commit e6e35df
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,36 @@ function populate (arg, start = 0) {
}
}

function bench (n = 0, x = 1) {
seed();
function get (arg, start = 0) {
const nth = arg.max;
let i = -1;

const timer = precise().start();
while (++i < nth) {
arg.get(i + start, data[i]);
}
}

populate(cache, n);
timer.stop();
console.log(`Run ${x} ${x === 1 ? "Set" : "Evict"} (${n === 0 ? "Low Keys" : "High Keys"}): ${timer.diff() / 1e6} ms`);
function bench (n = 0, x = 1, type = "set") {
if (type === "set") {
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`);
} else if (type === "get") {
const timer = precise().start();

get(cache, n);
timer.stop();
console.log(`Run ${x} Get (${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);
bench(nth, 5, "get");

0 comments on commit e6e35df

Please sign in to comment.