Skip to content

Commit 1184bd6

Browse files
author
Ruben Bridgewater
committed
Add big data to benchmark
1 parent adc47d0 commit 1184bd6

File tree

1 file changed

+61
-8
lines changed

1 file changed

+61
-8
lines changed

benchmark/index.js

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
var Benchmark = require('benchmark');
2-
var assert = require('assert');
3-
var suite = new Benchmark.Suite;
2+
var suite = new Benchmark.Suite();
43

5-
var Parser = require('./../lib/parser');
4+
var Parser = require('./../');
65
var ParserOLD = require('./old/parser');
76

8-
function returnError(error) {
9-
// throw error; silent for err error perf test
7+
function returnError (error) {
8+
error = null;
109
}
1110

12-
function checkReply() {
11+
function checkReply () {}
12+
13+
function shuffle (array) {
14+
var currentIndex = array.length;
15+
var temporaryValue;
16+
var randomIndex;
17+
18+
// While there remain elements to shuffle...
19+
while (currentIndex !== 0) {
20+
// Pick a remaining element...
21+
randomIndex = Math.floor(Math.random() * currentIndex);
22+
currentIndex -= 1;
23+
24+
// And swap it with the current element.
25+
temporaryValue = array[currentIndex];
26+
array[currentIndex] = array[randomIndex];
27+
array[randomIndex] = temporaryValue;
28+
}
29+
30+
return array;
1331
}
1432

1533
var startBuffer = new Buffer('$100\r\nabcdefghij');
@@ -19,6 +37,16 @@ var integerBuffer = new Buffer(':1237884\r\n');
1937
var errorBuffer = new Buffer('-Error ohnoesitbroke\r\n');
2038
var arrayBuffer = new Buffer('*1\r\n*1\r\n$1\r\na\r\n');
2139
var endBuffer = new Buffer('\r\n');
40+
var lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, ' +
41+
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' +
42+
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ' +
43+
'ut aliquip ex ea commodo consequat. Duis aute irure dolor in'; // 256 chars
44+
var bigStringArray = (new Array(Math.pow(2, 16) / lorem.length).join(lorem + ' ')).split(' '); // Math.pow(2, 16) chars long
45+
var startBigBuffer = new Buffer('$' + (4 * 1024 * 1024) + '\r\n' + lorem);
46+
var chunks = new Array(64);
47+
for (var i = 0; i < 64; i++) {
48+
chunks[i] = new Buffer(shuffle(bigStringArray).join(' ') + '.'); // Math.pow(2, 16) chars long
49+
}
2250

2351
var parserOld = new ParserOLD({
2452
returnReply: checkReply,
@@ -67,6 +95,32 @@ suite.add('NEW CODE: multiple chunks in a bulk string', function () {
6795
parser.execute(endBuffer);
6896
});
6997

98+
// BIG BULK STRING
99+
100+
suite.add('\nOLD CODE: 4mb bulk string', function () {
101+
parserOld.execute(startBigBuffer);
102+
for (var i = 0; i < 64; i++) {
103+
parserOld.execute(chunks[i]);
104+
}
105+
parserOld.execute(endBuffer);
106+
});
107+
108+
suite.add('HIREDIS: 4mb bulk string', function () {
109+
parserHiRedis.execute(startBigBuffer);
110+
for (var i = 0; i < 64; i++) {
111+
parserHiRedis.execute(chunks[i]);
112+
}
113+
parserHiRedis.execute(endBuffer);
114+
});
115+
116+
suite.add('NEW CODE: 4mb bulk string', function () {
117+
parser.execute(startBigBuffer);
118+
for (var i = 0; i < 64; i++) {
119+
parser.execute(chunks[i]);
120+
}
121+
parser.execute(endBuffer);
122+
});
123+
70124
// STRINGS
71125

72126
suite.add('\nOLD CODE: + simple string', function () {
@@ -134,5 +188,4 @@ suite.on('complete', function () {
134188
console.log('\n\nFastest is ' + this.filter('fastest').map('name'));
135189
});
136190

137-
138-
suite.run({delay:2, minSamples: 100 });
191+
suite.run({ delay: 1, minSamples: 150 });

0 commit comments

Comments
 (0)