Skip to content

Instantly share code, notes, and snippets.

@seriousManual
Created October 8, 2019 08:59
Show Gist options
  • Save seriousManual/dc12c6ba15a1771362880791f4901e09 to your computer and use it in GitHub Desktop.
Save seriousManual/dc12c6ba15a1771362880791f4901e09 to your computer and use it in GitHub Desktop.
const hirestime = require('hirestime');
const Redis = require('ioredis');
const stats = require('stats-lite');
const client = new Redis('redis://redis:6379');
const MAX_CARDINALITY = 1e6;
const times = [];
const timesGet = [];
const loopIterations = 1e4;
const KEY = `key_${Math.floor(Math.random() * 100000)}`;
async function execute() {
for (let i = 0; i < loopIterations; i++) {
const value = Math.floor(Math.random() * MAX_CARDINALITY);
const getElapsed = hirestime();
await client.pfadd(KEY, value);
times.push(getElapsed(hirestime.MS));
}
console.log(stats.mean(times));
console.log(stats.median(times));
for (let i = 0; i < loopIterations; i++) {
const getElapsed = hirestime();
a = await client.pfcount(KEY);
timesGet.push(getElapsed(hirestime.MS));
}
console.log(stats.mean(timesGet));
console.log(stats.median(timesGet));
}
execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment