1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

Started ./bench.js

This commit is contained in:
Tj Holowaychuk
2010-09-17 17:49:47 -07:00
parent 8e7f1cc1e7
commit ebf517e825

45
bench.js Normal file
View File

@@ -0,0 +1,45 @@
/**
* Module dependencies.
*/
var redis = require('./index')
, fs = require('fs');
var client = redis.createClient()
, path = '/tmp/redis-bench'
, times = 20000;
client.on('connect', function(){
try {
var prev = JSON.parse(fs.readFileSync(path, 'ascii'));
} catch (err) {
var prev = {};
}
benchmark(prev, {});
});
function benchmark(prev, curr) {
var n = times
, start = new Date;
console.log('\n %d:', times);
while (n--) client.lpush('list', 'foo');
client.lpush("list", "bar", function(err, res) {
curr.lpush = new Date - start;
report(prev, curr);
});
}
function report(prev, curr) {
for (var label in curr) {
var p = prev[label] || 0
, c = curr[label]
, col = c > p ? 31 : 32;
console.log(' \x1b[' + col + 'm%s\x1b[0m:', label);
console.log(' \x1b[33mprev\x1b[0m: %d ms', p);
console.log(' \x1b[33mcurr\x1b[0m: %d ms', c);
}
fs.writeFileSync(path, JSON.stringify(curr), 'ascii');
console.log();
client.end();
}