1
1
var Benchmark = require ( 'benchmark' ) ;
2
- var assert = require ( 'assert' ) ;
3
- var suite = new Benchmark . Suite ;
2
+ var suite = new Benchmark . Suite ( ) ;
4
3
5
- var Parser = require ( './../lib/parser ' ) ;
4
+ var Parser = require ( './../' ) ;
6
5
var ParserOLD = require ( './old/parser' ) ;
7
6
8
- function returnError ( error ) {
9
- // throw error; silent for err error perf test
7
+ function returnError ( error ) {
8
+ error = null ;
10
9
}
11
10
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 ;
13
31
}
14
32
15
33
var startBuffer = new Buffer ( '$100\r\nabcdefghij' ) ;
@@ -19,6 +37,16 @@ var integerBuffer = new Buffer(':1237884\r\n');
19
37
var errorBuffer = new Buffer ( '-Error ohnoesitbroke\r\n' ) ;
20
38
var arrayBuffer = new Buffer ( '*1\r\n*1\r\n$1\r\na\r\n' ) ;
21
39
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
+ }
22
50
23
51
var parserOld = new ParserOLD ( {
24
52
returnReply : checkReply ,
@@ -67,6 +95,32 @@ suite.add('NEW CODE: multiple chunks in a bulk string', function () {
67
95
parser . execute ( endBuffer ) ;
68
96
} ) ;
69
97
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
+
70
124
// STRINGS
71
125
72
126
suite . add ( '\nOLD CODE: + simple string' , function ( ) {
@@ -134,5 +188,4 @@ suite.on('complete', function () {
134
188
console . log ( '\n\nFastest is ' + this . filter ( 'fastest' ) . map ( 'name' ) ) ;
135
189
} ) ;
136
190
137
-
138
- suite . run ( { delay :2 , minSamples : 100 } ) ;
191
+ suite . run ( { delay : 1 , minSamples : 150 } ) ;
0 commit comments