|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 | var childProcess = require('child_process');
|
4 |
| -var nodeRedis = require('redis'); |
5 |
| -var IORedis = require('../'); |
6 |
| -var ndredis, ioredis; |
| 4 | +var Redis = require('../'); |
7 | 5 |
|
8 | 6 | console.log('==========================');
|
9 |
| -console.log('ioredis: ' + require('../package.json').version); |
10 |
| -console.log('node_redis: ' + require('redis/package.json').version); |
| 7 | +console.log('redis: ' + require('../package.json').version); |
11 | 8 | var os = require('os');
|
12 | 9 | console.log('CPU: ' + os.cpus().length);
|
13 | 10 | console.log('OS: ' + os.platform() + ' ' + os.arch());
|
14 | 11 | console.log('node version: ' + process.version);
|
15 | 12 | console.log('current commit: ' + childProcess.execSync('git rev-parse --short HEAD'));
|
16 | 13 | console.log('==========================');
|
17 | 14 |
|
| 15 | +var redisJD, redisJ, redisBD, redisB; |
18 | 16 | var waitReady = function (next) {
|
19 |
| - var pending = 2; |
20 |
| - ndredis.on('ready', function () { |
| 17 | + var pending = 4; |
| 18 | + function check() { |
21 | 19 | if (!--pending) {
|
22 | 20 | next();
|
23 | 21 | }
|
24 |
| - }); |
| 22 | + } |
| 23 | + redisJD = new Redis({ parser: 'javascript', dropBufferSupport: true }); |
| 24 | + redisJ = new Redis({ parser: 'javascript', dropBufferSupport: false }); |
| 25 | + redisBD = new Redis({ parser: 'hiredis', dropBufferSupport: true }); |
| 26 | + redisB = new Redis({ parser: 'hiredis', dropBufferSupport: false }); |
| 27 | + redisJD.on('ready', check); |
| 28 | + redisJ.on('ready', check); |
| 29 | + redisBD.on('ready', check); |
| 30 | + redisB.on('ready', check); |
| 31 | +}; |
25 | 32 |
|
26 |
| - ioredis.on('ready', function () { |
27 |
| - if (!--pending) { |
28 |
| - next(); |
29 |
| - } |
30 |
| - }); |
| 33 | +var quit = function () { |
| 34 | + redisJD.quit(); |
| 35 | + redisJ.quit(); |
| 36 | + redisBD.quit(); |
| 37 | + redisB.quit(); |
31 | 38 | };
|
32 | 39 |
|
33 |
| -suite('simple set', function () { |
| 40 | +suite('SET foo bar', function () { |
34 | 41 | set('mintime', 5000);
|
35 | 42 | set('concurrency', 300);
|
36 | 43 | before(function (start) {
|
37 |
| - ndredis = nodeRedis.createClient(); |
38 |
| - ioredis = new IORedis(); |
39 | 44 | waitReady(start);
|
40 | 45 | });
|
41 | 46 |
|
42 |
| - bench('ioredis', function (next) { |
43 |
| - ioredis.set('foo', 'bar', next); |
44 |
| - }); |
45 |
| - |
46 |
| - bench('node_redis', function (next) { |
47 |
| - ndredis.set('foo', 'bar', next); |
| 47 | + bench('javascript parser + dropBufferSupport: true', function (next) { |
| 48 | + redisJD.set('foo', 'bar', next); |
48 | 49 | });
|
49 | 50 |
|
50 |
| - after(function () { |
51 |
| - ndredis.quit(); |
52 |
| - ioredis.quit(); |
53 |
| - }); |
54 |
| -}); |
55 |
| - |
56 |
| -suite('simple get', function () { |
57 |
| - set('mintime', 5000); |
58 |
| - set('concurrency', 300); |
59 |
| - before(function (start) { |
60 |
| - ndredis = nodeRedis.createClient(); |
61 |
| - ioredis = new IORedis(); |
62 |
| - waitReady(function () { |
63 |
| - ndredis.set('foo', 'bar', start); |
64 |
| - }); |
| 51 | + bench('javascript parser', function (next) { |
| 52 | + redisJ.setBuffer('foo', 'bar', next); |
65 | 53 | });
|
66 | 54 |
|
67 |
| - bench('ioredis', function (next) { |
68 |
| - ioredis.get('foo', next); |
| 55 | + bench('hiredis parser + dropBufferSupport: true', function (next) { |
| 56 | + redisBD.set('foo', 'bar', next); |
69 | 57 | });
|
70 | 58 |
|
71 |
| - bench('node_redis', function (next) { |
72 |
| - ndredis.get('foo', next); |
| 59 | + bench('hiredis parser', function (next) { |
| 60 | + redisB.setBuffer('foo', 'bar', next); |
73 | 61 | });
|
74 | 62 |
|
75 |
| - after(function () { |
76 |
| - ndredis.quit(); |
77 |
| - ioredis.quit(); |
78 |
| - }); |
| 63 | + after(quit); |
79 | 64 | });
|
80 | 65 |
|
81 |
| -suite('simple get with pipeline', function () { |
| 66 | +suite('LRANGE foo 0 99', function () { |
82 | 67 | set('mintime', 5000);
|
83 | 68 | set('concurrency', 300);
|
84 | 69 | before(function (start) {
|
85 |
| - ndredis = nodeRedis.createClient(); |
86 |
| - ioredis = new IORedis(); |
87 |
| - waitReady(function () { |
88 |
| - ndredis.set('foo', 'bar', start); |
89 |
| - }); |
90 |
| - }); |
91 |
| - |
92 |
| - bench('ioredis', function (next) { |
93 |
| - var pipeline = ioredis.pipeline(); |
94 |
| - for (var i = 0; i < 10; ++i) { |
95 |
| - pipeline.get('foo'); |
96 |
| - } |
97 |
| - pipeline.exec(next); |
98 |
| - }); |
99 |
| - |
100 |
| - bench('node_redis', function (next) { |
101 |
| - var pending = 0; |
102 |
| - for (var i = 0; i < 10; ++i) { |
103 |
| - pending += 1; |
104 |
| - ndredis.get('foo', check); |
| 70 | + var redis = new Redis(); |
| 71 | + var item = []; |
| 72 | + for (var i = 0; i < 100; ++i) { |
| 73 | + item.push((Math.random() * 100000 | 0) + 'str'); |
105 | 74 | }
|
106 |
| - function check() { |
107 |
| - if (!--pending) { |
108 |
| - next(); |
109 |
| - } |
110 |
| - } |
111 |
| - }); |
112 |
| - |
113 |
| - after(function () { |
114 |
| - ndredis.quit(); |
115 |
| - ioredis.quit(); |
116 |
| - }); |
117 |
| -}); |
118 |
| - |
119 |
| -suite('lrange 100', function () { |
120 |
| - set('mintime', 5000); |
121 |
| - set('concurrency', 300); |
122 |
| - before(function (start) { |
123 |
| - ndredis = nodeRedis.createClient(); |
124 |
| - ioredis = new IORedis(); |
125 |
| - waitReady(function () { |
126 |
| - var item = []; |
127 |
| - for (var i = 0; i < 100; ++i) { |
128 |
| - item.push((Math.random() * 100000 | 0) + 'str'); |
129 |
| - } |
130 |
| - ndredis.del('foo'); |
131 |
| - ndredis.lpush('foo', item, start); |
132 |
| - }); |
133 |
| - }); |
134 |
| - |
135 |
| - bench('ioredis', function (next) { |
136 |
| - ioredis.lrange('foo', 0, 99, next); |
137 |
| - }); |
138 |
| - |
139 |
| - bench('node_redis', function (next) { |
140 |
| - ndredis.lrange('foo', 0, 99, next); |
141 |
| - }); |
142 |
| - |
143 |
| - after(function () { |
144 |
| - ndredis.quit(); |
145 |
| - ioredis.quit(); |
146 |
| - }); |
147 |
| -}); |
148 |
| - |
149 |
| -suite('publish', function () { |
150 |
| - set('mintime', 5000); |
151 |
| - set('concurrency', 300); |
152 |
| - |
153 |
| - before(function (start) { |
154 |
| - ndredis = nodeRedis.createClient(); |
155 |
| - ioredis = new IORedis(); |
156 |
| - waitReady(function () { |
157 |
| - start(); |
| 75 | + redis.del('foo'); |
| 76 | + redis.lpush('foo', item, function () { |
| 77 | + waitReady(start); |
158 | 78 | });
|
159 | 79 | });
|
160 | 80 |
|
161 |
| - bench('ioredis', function (next) { |
162 |
| - ioredis.publish('foo', 'bar', next); |
163 |
| - }); |
164 |
| - |
165 |
| - bench('node_redis', function (next) { |
166 |
| - ndredis.publish('foo', 'bar', next); |
| 81 | + bench('javascript parser + dropBufferSupport: true', function (next) { |
| 82 | + redisJD.lrange('foo', 0, 99, next); |
167 | 83 | });
|
168 | 84 |
|
169 |
| - after(function () { |
170 |
| - ndredis.quit(); |
171 |
| - ioredis.quit(); |
172 |
| - }); |
173 |
| -}); |
174 |
| - |
175 |
| -suite('subscribe', function () { |
176 |
| - set('mintime', 5000); |
177 |
| - set('concurrency', 300); |
178 |
| - |
179 |
| - var ndpublisher = null; |
180 |
| - var iopublisher = null; |
181 |
| - var ndsubscriber = null; |
182 |
| - var iosubscriber = null; |
183 |
| - |
184 |
| - before(function (start) { |
185 |
| - ndredis = nodeRedis.createClient(); |
186 |
| - ioredis = new IORedis(); |
187 |
| - waitReady(function () { |
188 |
| - ndsubscriber = ndredis; |
189 |
| - ndsubscriber.subscribe('foo'); |
190 |
| - iosubscriber = ioredis; |
191 |
| - iosubscriber.subscribe('foo'); |
192 |
| - |
193 |
| - ndredis = nodeRedis.createClient(); |
194 |
| - ioredis = new IORedis(); |
195 |
| - waitReady(function () { |
196 |
| - ndpublisher = ndredis; |
197 |
| - iopublisher = ioredis; |
198 |
| - start(); |
199 |
| - }); |
200 |
| - }); |
| 85 | + bench('javascript parser', function (next) { |
| 86 | + redisJ.lrangeBuffer('foo', 0, 99, next); |
201 | 87 | });
|
202 | 88 |
|
203 |
| - bench('ioredis', function (next) { |
204 |
| - iosubscriber.removeAllListeners('message'); |
205 |
| - ndsubscriber.removeAllListeners('message'); |
206 |
| - iosubscriber.on('message', next); |
207 |
| - iopublisher.publish('foo', 'bar'); |
| 89 | + bench('hiredis parser + dropBufferSupport: true', function (next) { |
| 90 | + redisBD.lrange('foo', 0, 99, next); |
208 | 91 | });
|
209 | 92 |
|
210 |
| - bench('node_redis', function (next) { |
211 |
| - iosubscriber.removeAllListeners('message'); |
212 |
| - ndsubscriber.removeAllListeners('message'); |
213 |
| - ndsubscriber.on('message', next); |
214 |
| - ndpublisher.publish('foo', 'bar'); |
| 93 | + bench('hiredis parser', function (next) { |
| 94 | + redisB.lrangeBuffer('foo', 0, 99, next); |
215 | 95 | });
|
216 | 96 |
|
217 |
| - after(function () { |
218 |
| - ndredis.quit(); |
219 |
| - ioredis.quit(); |
220 |
| - }); |
| 97 | + after(quit); |
221 | 98 | });
|
0 commit comments