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

Benchmarking different buffer sizes

This commit is contained in:
Tj Holowaychuk
2010-09-17 18:32:24 -07:00
parent 044e2d1af9
commit 4a85e03d35

View File

@@ -8,12 +8,30 @@ var redis = require('./index')
var client = redis.createClient() var client = redis.createClient()
, path = '/tmp/redis-bench' , path = '/tmp/redis-bench'
, times = 20000 , times = 10000
, curr = {} , curr = {}
, prev; , prev;
var buffers = [
new Buffer('hello')
, new Buffer(Array(129).join('-'))
, new Buffer(Array(257).join('-'))
, new Buffer(Array(1025).join('-'))
, new Buffer(Array(1025 * 4).join('-'))
];
function next(){ function next(){
queue.shift()(); var fn = queue.shift();
if (fn.length) {
var pending = buffers.length;
buffers.forEach(function(buf){
fn(buf, function(){
--pending || next();
});
});
} else {
fn();
}
} }
var queue = [ var queue = [
@@ -26,24 +44,24 @@ var queue = [
// LPUSH // LPUSH
function(){ function(buf, next){
var n = times var n = times
, start = new Date; , start = new Date;
while (n--) client.lpush('list', 'foo'); while (n--) client.lpush('list', 'foo');
client.lpush("list", "bar", function(err, res) { client.lpush("list", buf, function(err, res) {
curr.lpush = new Date - start; curr['lpush ' + buf.length] = new Date - start;
next(); next();
}); });
}, },
// LRANGE // LRANGE
function(){ function(buf, next){
var n = times var n = times
, start = new Date; , start = new Date;
while (n--) client.lrange("mylist", 0, 99); while (n--) client.lrange("mylist", 0, 99);
client.lrange("mylist", 0, 99, function (err, res) { client.lrange("mylist", 0, 99, function (err, res) {
curr.lrange = new Date - start; curr['lrange ' + buf.length] = new Date - start;
next(); next();
}); });
}, },