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

No longer passing around curr/prev

This commit is contained in:
Tj Holowaychuk
2010-09-17 18:00:29 -07:00
parent a05b322709
commit 729debf993

View File

@@ -8,29 +8,31 @@ var redis = require('./index')
var client = redis.createClient() var client = redis.createClient()
, path = '/tmp/redis-bench' , path = '/tmp/redis-bench'
, times = 20000; , times = 20000
, curr = {}
, prev;
client.on('connect', function(){ client.on('connect', function(){
try { try {
var prev = JSON.parse(fs.readFileSync(path, 'ascii')); prev = JSON.parse(fs.readFileSync(path, 'ascii'));
} catch (err) { } catch (err) {
var prev = {}; prev = {};
} }
benchmark(prev, {}); benchmark();
}); });
function benchmark(prev, curr) { function benchmark() {
var n = times var n = times
, start = new Date; , start = new Date;
console.log('\n %d:', times); console.log('\n %d:', times);
while (n--) client.lpush('list', 'foo'); while (n--) client.lpush('list', 'foo');
client.lpush("list", "bar", function(err, res) { client.lpush("list", "bar", function(err, res) {
curr.lpush = new Date - start; curr.lpush = new Date - start;
report(prev, curr); report();
}); });
} }
function report(prev, curr) { function report() {
for (var label in curr) { for (var label in curr) {
var p = prev[label] || 0 var p = prev[label] || 0
, c = curr[label] , c = curr[label]