public
Created

parser speed comparison node_redis vs. node-redjs

  • Download Gist
readme.markdown
Markdown

Two instances of each parser are created. Each test is run 10 times for each parser instance. One test consists of 65536 replies in one buffer.

sum is the time in ns for parsing ALL 655360 replies.

mean is the time in ns for parsing e.g. ONE +OK\r\n reply.

65536 x +OK\r\n
[ { name: 'redisv2_1', sum: 333492995, mean: 508.8699264526367 },
  { name: 'redjsv2_1', sum: 144464797, mean: 220.43578643798827 },
  { name: 'redisv2_2', sum: 200465605, mean: 305.88623809814453 },
  { name: 'redjsv2_2', sum: 148304758, mean: 226.29510192871095 } ]
65536 x -ERR Unknown command\r\n
[ { name: 'redisv2_1', sum: 841495954, mean: 1284.0209259033204 },
  { name: 'redjsv2_1', sum: 584473731, mean: 891.8361373901367 },
  { name: 'redisv2_2', sum: 834551578, mean: 1273.4246490478515 },
  { name: 'redjsv2_2', sum: 585647605, mean: 893.627326965332 } ]
65536 x :1\r\n
[ { name: 'redisv2_1', sum: 335402042, mean: 511.78290100097655 },
  { name: 'redjsv2_1', sum: 118247328, mean: 180.431103515625 },
  { name: 'redisv2_2', sum: 199370702, mean: 304.2155487060547 },
  { name: 'redjsv2_2', sum: 122943718, mean: 187.59722595214845 } ]
65536 x :32487216\r\n
[ { name: 'redisv2_1', sum: 587642318, mean: 896.6710174560546 },
  { name: 'redjsv2_1', sum: 400243945, mean: 610.7237930297852 },
  { name: 'redisv2_2', sum: 459096153, mean: 700.5251358032226 },
  { name: 'redjsv2_2', sum: 399526369, mean: 609.6288589477539 } ]
65536 x $11\r\nhello world\r\n
[ { name: 'redisv2_1', sum: 913061207, mean: 1393.220835876465 },
  { name: 'redjsv2_1', sum: 572391750, mean: 873.4004974365234 },
  { name: 'redisv2_2', sum: 663847384, mean: 1012.9507202148437 },
  { name: 'redjsv2_2', sum: 574731813, mean: 876.9711502075195 } ]
65536 x $62\r\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\r\n
[ { name: 'redisv2_1', sum: 965753458, mean: 1473.6228302001953 },
  { name: 'redjsv2_1', sum: 717923752, mean: 1095.4647094726563 },
  { name: 'redisv2_2', sum: 742469194, mean: 1132.9180816650392 },
  { name: 'redjsv2_2', sum: 719639203, mean: 1098.0822799682617 } ]
65536 x *2\r\n$11\r\nhello world\r\n$4\r\ntest\r\n
[ { name: 'redisv2_1', sum: 1749351947, mean: 2669.299235534668 },
  { name: 'redjsv2_1', sum: 989924903, mean: 1510.5055282592773 },
  { name: 'redisv2_2', sum: 1422842028, mean: 2171.084637451172 },
  { name: 'redjsv2_2', sum: 990478749, mean: 1511.3506301879884 } ]
65536 x *2\r\n$11\r\nhello world\r\n*2\r\n*2\r\n$-1\r\n:1\r\n$4\r\ntest\r\n
[ { name: 'redisv2_1', sum: 2901470376, mean: 4427.292443847657 },
  { name: 'redjsv2_1', sum: 1636275543, mean: 2496.758335876465 },
  { name: 'redisv2_2', sum: 2613921148, mean: 3988.5271423339846 },
  { name: 'redjsv2_2', sum: 1627842155, mean: 2483.890007019043 } ]
test.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
'use strict';
 
var ParserRedjsV2 = require('./lib/parser');
var ParserRedisV2 = require('./node_modules/redis/lib/parser/javascript').Parser;
 
var redisv2_1 = new ParserRedisV2({debug_mode: false});
redisv2_1.on('reply', function(result) {});
 
var redjsv2_1 = new ParserRedjsV2();
redjsv2_1.on('reply', function(type, result) {});
 
var redisv2_2 = new ParserRedisV2({debug_mode: false});
redisv2_2.on('reply', function(result) {});
 
var redjsv2_2 = new ParserRedjsV2();
redjsv2_2.on('reply', function(type, result) {});
 
var parsers = [
{name: 'redisv2_1', write: function(data) {
redisv2_1.execute(data);
}},
{name: 'redjsv2_1', write: function(data) {
redjsv2_1.write(data);
}},
{name: 'redisv2_2', write: function(data) {
redisv2_2.execute(data);
}},
{name: 'redjsv2_2', write: function(data) {
redjsv2_2.write(data);
}},
];
 
function test(parsers, data, numRuns) {
var d, j;
var results = [];
var l = parsers.length;
var i = numRuns * l;
 
var tx = 0;
var txc = 1;
var data_ = data;
 
do {
txc += txc;
data += data;
} while (++tx < 16);
console.log('%s x %s', txc, data_.replace(/\r\n/g, '\\r\\n'));
 
data = new Buffer(data);
 
do {
j = i % l;
d = process.hrtime();
parsers[j].write(data);
d = process.hrtime(d);
 
results[j] = results[j] || {name: parsers[j].name, sum: 0, mean: 0};
 
results[j].sum += ((d[0] * 1e9) + d[1]);
results[j].mean = results[j].sum / numRuns / txc;
} while (--i);
 
console.log(results);
}
 
var count = 10;
 
test(parsers, '+OK\r\n', count);
test(parsers, '-ERR Unknown command\r\n', count);
test(parsers, ':1\r\n', count);
test(parsers, ':32487216\r\n', count);
test(parsers, '$11\r\nhello world\r\n', count);
test(parsers, '$62\r\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\r\n', count);
test(parsers, '*2\r\n$11\r\nhello world\r\n$4\r\ntest\r\n', count);
test(parsers, '*2\r\n$11\r\nhello world\r\n*2\r\n*2\r\n$-1\r\n:1\r\n$4\r\ntest\r\n', count);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.