From ebf517e825cbc6d36874f84cc3292e7fe2448cfd Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Fri, 17 Sep 2010 17:49:47 -0700 Subject: [PATCH] Started ./bench.js --- bench.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 bench.js diff --git a/bench.js b/bench.js new file mode 100644 index 0000000000..6b8874d57b --- /dev/null +++ b/bench.js @@ -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(); +} \ No newline at end of file