|
7 | 7 |
|
8 | 8 | WaitQueue is an async implements of Array
|
9 | 9 |
|
| 10 | +## Table of Contents |
| 11 | + |
| 12 | +- [How to use](#how-to-use) |
| 13 | +- [Requirements](#requirements) |
| 14 | +- [Change Log](#change-log) |
| 15 | +- [Properties](#properties) |
| 16 | +- [Methods](#methods) |
| 17 | +- [Benchmark](#benchmark) |
| 18 | + |
| 19 | +Examples |
| 20 | + |
| 21 | +- [Iterator](#iterator) |
| 22 | +- [Multi Worker](#example-multi-worker) |
| 23 | +- [Push a function](#example-push-a-function) |
| 24 | +- [Loop Tasks](#example-loop-tasks) |
| 25 | +- [Using with co](#using-with-co) |
| 26 | + |
10 | 27 | ## How to use
|
11 | 28 |
|
12 | 29 | ```shell
|
@@ -95,7 +112,55 @@ Clear the queue, Won't clear listeners
|
95 | 112 |
|
96 | 113 | Clear waited listeners of the queue
|
97 | 114 |
|
98 |
| -## use for ... of to get all values |
| 115 | + |
| 116 | +## Benchmark |
| 117 | + |
| 118 | +``` |
| 119 | +$ git clone https://github.com/flarestart/wait-queue.git |
| 120 | +$ cd wait-queue |
| 121 | +$ npm install |
| 122 | +$ npm run benchmark |
| 123 | +``` |
| 124 | + |
| 125 | +Sample data in Macbook Pro MF839/8GB |
| 126 | + |
| 127 | +### 1.1.0(Improve benchmark code) |
| 128 | + |
| 129 | + Array.push(1k data) speed test x 629,538 ops/sec ±22.90% (26 runs sampled) |
| 130 | + Array.push(1k data) 1000000 times then Array.shift() speed test x 492 ops/sec ±1.02% (89 runs sampled) |
| 131 | + WaitQueue.push(1k data) speed test x 501,581 ops/sec ±23.45% (14 runs sampled) |
| 132 | + WaitQueue.unshift(1k data) speed test x 447,272 ops/sec ±24.80% (14 runs sampled) |
| 133 | + WaitQueue.shift() speed test x 315,356 ops/sec ±14.30% (52 runs sampled) |
| 134 | + WaitQueue.pop() speed test x 240,568 ops/sec ±51.35% (39 runs sampled) |
| 135 | + WaitQueue.push(1k data) 1000000 times then WaitQueue.shift() speed test x 476,918 ops/sec ±26.68% (29 runs sampled) |
| 136 | + WaitQueue.push(1k data) 1000000 times then WaitQueue.pop() speed test x 471,668 ops/sec ±25.08% (31 runs sampled) |
| 137 | + Array.push(4k data) speed test x 119,981 ops/sec ±61.52% (14 runs sampled) |
| 138 | + Array.push(4k data) 1000000 times then Array.shift() speed test x 479 ops/sec ±1.41% (86 runs sampled) |
| 139 | + WaitQueue.push(4k data) speed test x 147,153 ops/sec ±46.03% (14 runs sampled) |
| 140 | + WaitQueue.unshift(4k data) speed test x 157,694 ops/sec ±37.29% (16 runs sampled) |
| 141 | + WaitQueue.push(4k data) 1000000 times then WaitQueue.shift() speed test x 447,783 ops/sec ±28.01% (31 runs sampled) |
| 142 | + WaitQueue.push(4k data) 1000000 times then WaitQueue.pop() speed test x 409,826 ops/sec ±30.73% (28 runs sampled) |
| 143 | + |
| 144 | +### 1.0.3(Use LinkList) |
| 145 | + |
| 146 | + .push() 1k data speed test x 511,367 ops/sec ±31.07% (27 runs sampled) |
| 147 | + .unshift() 1k data speed test x 269,995 ops/sec ±39.60% (14 runs sampled) |
| 148 | + .push() 4k data speed test x 41,531 ops/sec ±12.20% (7 runs sampled) |
| 149 | + .unshift() 4k data speed test x 35,928 ops/sec ±5.11% (8 runs sampled) |
| 150 | + .shift() 69614.33093950555 /s |
| 151 | + |
| 152 | +### 1.0.2(Use Array) |
| 153 | + |
| 154 | + .push() 1k data speed test x 554,552 ops/sec ±26.09% (25 runs sampled) |
| 155 | + .unshift() 1k data speed test x 132 ops/sec ±2.96% (72 runs sampled) |
| 156 | + .push() 4k data speed test x 75,107 ops/sec ±22.32% (9 runs sampled) |
| 157 | + .unshift() 4k data speed test x 115 ops/sec ±2.15% (71 runs sampled) |
| 158 | + .shift() `wait too long, I didn't wait for the result, I guess is about 110/s` |
| 159 | + |
| 160 | + |
| 161 | +## Example: Iterator |
| 162 | + |
| 163 | +use for ... of to get all values |
99 | 164 |
|
100 | 165 | ```js
|
101 | 166 | 'use strict'
|
@@ -243,50 +308,6 @@ setInterval(function(){
|
243 | 308 |
|
244 | 309 | ```
|
245 | 310 |
|
246 |
| -## Benchmark |
247 |
| - |
248 |
| -``` |
249 |
| -$ git clone https://github.com/flarestart/wait-queue.git |
250 |
| -$ cd wait-queue |
251 |
| -$ npm install |
252 |
| -$ npm run benchmark |
253 |
| -``` |
254 |
| - |
255 |
| -Sample data in Macbook Pro MF839/8GB |
256 |
| - |
257 |
| -### 1.1.0(Improve benchmark code) |
258 |
| - |
259 |
| - Array.push(1k data) speed test x 629,538 ops/sec ±22.90% (26 runs sampled) |
260 |
| - Array.push(1k data) 1000000 times then Array.shift() speed test x 492 ops/sec ±1.02% (89 runs sampled) |
261 |
| - WaitQueue.push(1k data) speed test x 501,581 ops/sec ±23.45% (14 runs sampled) |
262 |
| - WaitQueue.unshift(1k data) speed test x 447,272 ops/sec ±24.80% (14 runs sampled) |
263 |
| - WaitQueue.shift() speed test x 315,356 ops/sec ±14.30% (52 runs sampled) |
264 |
| - WaitQueue.pop() speed test x 240,568 ops/sec ±51.35% (39 runs sampled) |
265 |
| - WaitQueue.push(1k data) 1000000 times then WaitQueue.shift() speed test x 476,918 ops/sec ±26.68% (29 runs sampled) |
266 |
| - WaitQueue.push(1k data) 1000000 times then WaitQueue.pop() speed test x 471,668 ops/sec ±25.08% (31 runs sampled) |
267 |
| - Array.push(4k data) speed test x 119,981 ops/sec ±61.52% (14 runs sampled) |
268 |
| - Array.push(4k data) 1000000 times then Array.shift() speed test x 479 ops/sec ±1.41% (86 runs sampled) |
269 |
| - WaitQueue.push(4k data) speed test x 147,153 ops/sec ±46.03% (14 runs sampled) |
270 |
| - WaitQueue.unshift(4k data) speed test x 157,694 ops/sec ±37.29% (16 runs sampled) |
271 |
| - WaitQueue.push(4k data) 1000000 times then WaitQueue.shift() speed test x 447,783 ops/sec ±28.01% (31 runs sampled) |
272 |
| - WaitQueue.push(4k data) 1000000 times then WaitQueue.pop() speed test x 409,826 ops/sec ±30.73% (28 runs sampled) |
273 |
| - |
274 |
| -### 1.0.3(Use LinkList) |
275 |
| - |
276 |
| - .push() 1k data speed test x 511,367 ops/sec ±31.07% (27 runs sampled) |
277 |
| - .unshift() 1k data speed test x 269,995 ops/sec ±39.60% (14 runs sampled) |
278 |
| - .push() 4k data speed test x 41,531 ops/sec ±12.20% (7 runs sampled) |
279 |
| - .unshift() 4k data speed test x 35,928 ops/sec ±5.11% (8 runs sampled) |
280 |
| - .shift() 69614.33093950555 /s |
281 |
| - |
282 |
| -### 1.0.2(Use Array) |
283 |
| - |
284 |
| - .push() 1k data speed test x 554,552 ops/sec ±26.09% (25 runs sampled) |
285 |
| - .unshift() 1k data speed test x 132 ops/sec ±2.96% (72 runs sampled) |
286 |
| - .push() 4k data speed test x 75,107 ops/sec ±22.32% (9 runs sampled) |
287 |
| - .unshift() 4k data speed test x 115 ops/sec ±2.15% (71 runs sampled) |
288 |
| - .shift() `wait too long, I didn't wait for the result, I guess is about 110/s` |
289 |
| - |
290 | 311 | ## License
|
291 | 312 |
|
292 | 313 | MIT
|
|
0 commit comments