mranney/node_redis — pull request #188 by DTrejo (2012-03-12 19:53:47+00:00)
Title: index.js perf: remove .forEach in Multi.prototype.exec

I think there needs to be a better way to compare the performance before and after the change.

It's difficult to look at the numbers and be sure that it had a positive influence. Probably should have used a profiler first to see how hot the code path is — should have thought of that earlier.

**I don't think this is ready for merging** — I need to write a little script that examines the differences between the `node multibench.js` results for each run.

.forEach loops (5351 ms test.js):

```
Client count: 5, node version: 0.6.12, server version: 2.4.8, parser: hiredis
PING, 1/5 min/max/avg/p95: 0/ 6/ 0.10/ 1.00 2101ms total, 9519.28 ops/sec
PING, 50/5 min/max/avg/p95: 0/ 15/ 1.66/ 3.00 667ms total, 29985.01 ops/sec
PING, 200/5 min/max/avg/p95: 1/ 24/ 6.30/ 10.00 632ms total, 31645.57 ops/sec
PING, 20000/5 Client count: 5, node version: 0.6.12, server version: 2.4.8, parser: hiredis
PING, 1/5 min/max/avg/p95: 0/ 6/ 0.10/ 1.00 2106ms total, 9496.68 ops/sec
PING, 50/5 min/max/avg/p95: 0/ 19/ 1.76/ 3.00 705ms total, 28368.79 ops/sec
PING, 200/5 min/max/avg/p95: 1/ 22/ 6.32/ 11.00 635ms total, 31496.06 ops/sec
PING, 20000/5 min/max/avg/p95: 56/ 598/ 320.38/ 550.00 621ms total, 32206.12 ops/sec
SET small str, 1/5 min/max/avg/p95: 0/ 19/ 0.11/ 1.00 2220ms total, 9009.01 ops/sec
SET small str, 50/5 min/max/avg/p95: 0/ 34/ 1.81/ 3.00 728ms total, 27472.53 ops/sec
SET small str, 200/5 min/max/avg/p95: 0/ 17/ 6.51/ 11.00 653ms total, 30627.87 ops/sec
SET small str, 20000/5 min/max/avg/p95: 51/ 638/ 351.74/ 578.10 648ms total, 30864.20 ops/sec
SET small buf, 1/5 min/max/avg/p95: 0/ 19/ 0.16/ 1.00 3296ms total, 6067.96 ops/sec
SET small buf, 50/5 min/max/avg/p95: 0/ 27/ 5.10/ 8.00 2043ms total, 9789.53 ops/sec
SET small buf, 200/5 min/max/avg/p95: 0/ 68/ 20.77/ 34.00 2087ms total, 9583.13 ops/sec
SET small buf, 20000/5 min/max/avg/p95: 203/2100/1177.03/2003.20 2109ms total, 9483.17 ops/sec
GET small str, 1/5 min/max/avg/p95: 0/ 7/ 0.10/ 1.00 2093ms total, 9555.66 ops/sec
GET small str, 50/5 min/max/avg/p95: 0/ 30/ 1.68/ 3.00 675ms total, 29629.63 ops/sec
GET small str, 200/5 min/max/avg/p95: 0/ 22/ 6.37/ 10.00 639ms total, 31298.90 ops/sec
GET small str, 20000/5 min/max/avg/p95: 52/ 626/ 341.20/ 588.55 662ms total, 30211.48 ops/sec
GET small buf, 1/5 min/max/avg/p95: 0/ 7/ 0.10/ 1.00 2084ms total, 9596.93 ops/sec
GET small buf, 50/5 min/max/avg/p95: 0/ 23/ 1.65/ 3.00 663ms total, 30165.91 ops/sec
GET small buf, 200/5 min/max/avg/p95: 1/ 31/ 6.97/ 12.00 700ms total, 28571.43 ops/sec
GET small buf, 20000/5 min/max/avg/p95: 51/ 682/ 351.47/ 616.55 693ms total, 28860.03 ops/sec
SET large str, 1/5 min/max/avg/p95: 0/ 21/ 0.14/ 1.00 2920ms total, 6849.32 ops/sec
SET large str, 50/5 min/max/avg/p95: 0/ 27/ 3.31/ 5.00 1326ms total, 15082.96 ops/sec
SET large str, 200/5 min/max/avg/p95: 1/ 44/ 12.92/ 33.00 1297ms total, 15420.20 ops/sec
SET large str, 20000/5 min/max/avg/p95: 202/1715/ 961.46/1592.10 1748ms total, 11441.65 ops/sec
SET large buf, 1/5 min/max/avg/p95: 0/ 16/ 0.18/ 1.00 3605ms total, 5547.85 ops/sec
SET large buf, 50/5 min/max/avg/p95: 0/ 17/ 5.06/ 8.00 2026ms total, 9871.67 ops/sec
SET large buf, 200/5 min/max/avg/p95: 0/ 44/ 19.95/ 32.00 2005ms total, 9975.06 ops/sec
SET large buf, 20000/5 min/max/avg/p95: 200/2180/1220.56/2088.00 2189ms total, 9136.59 ops/sec
GET large str, 1/5 min/max/avg/p95: 0/ 20/ 0.11/ 1.00 2346ms total, 8525.15 ops/sec
GET large str, 50/5 min/max/avg/p95: 0/ 19/ 2.80/ 6.00 1121ms total, 17841.21 ops/sec
GET large str, 200/5 min/max/avg/p95: 0/ 46/ 9.53/ 24.00 958ms total, 20876.83 ops/sec
GET large str, 20000/5 min/max/avg/p95: 422/ 831/ 583.07/ 765.55 1130ms total, 17699.12 ops/sec
GET large buf, 1/5 min/max/avg/p95: 0/ 12/ 0.11/ 1.00 2348ms total, 8517.89 ops/sec
GET large buf, 50/5 min/max/avg/p95: 0/ 16/ 2.45/ 4.00 988ms total, 20242.91 ops/sec
GET large buf, 200/5 min/max/avg/p95: 0/ 33/ 9.38/ 20.00 942ms total, 21231.42 ops/sec
GET large buf, 20000/5 min/max/avg/p95: 361/ 691/ 548.64/ 659.55 1036ms total, 19305.02 ops/sec
INCR, 1/5 min/max/avg/p95: 0/ 17/ 0.11/ 1.00 2154ms total, 9285.05 ops/sec
INCR, 50/5 min/max/avg/p95: 0/ 20/ 1.71/ 3.00 685ms total, 29197.08 ops/sec
INCR, 200/5 min/max/avg/p95: 1/ 30/ 6.62/ 12.00 665ms total, 30075.19 ops/sec
INCR, 20000/5 min/max/avg/p95: 48/ 638/ 354.40/ 595.00 647ms total, 30911.90 ops/sec
LPUSH, 1/5 min/max/avg/p95: 0/ 7/ 0.10/ 1.00 2099ms total, 9528.35 ops/sec
LPUSH, 50/5 min/max/avg/p95: 0/ 25/ 1.70/ 3.00 681ms total, 29368.58 ops/sec
LPUSH, 200/5 min/max/avg/p95: 0/ 40/ 6.55/ 10.00 658ms total, 30395.14 ops/sec
LPUSH, 20000/5 min/max/avg/p95: 49/ 631/ 355.67/ 596.10 641ms total, 31201.25 ops/sec
LRANGE 10, 1/5 min/max/avg/p95: 0/ 19/ 0.12/ 1.00 2436ms total, 8210.18 ops/sec
LRANGE 10, 50/5 min/max/avg/p95: 0/ 20/ 1.95/ 3.00 782ms total, 25575.45 ops/sec
LRANGE 10, 200/5 min/max/avg/p95: 0/ 33/ 8.59/ 19.00 863ms total, 23174.97 ops/sec
LRANGE 10, 20000/5 min/max/avg/p95: 89/ 722/ 398.88/ 664.10 754ms total, 26525.20 ops/sec
LRANGE 100, 1/5 min/max/avg/p95: 0/ 16/ 0.21/ 1.00 4231ms total, 4727.01 ops/sec
LRANGE 100, 50/5 min/max/avg/p95: 1/ 17/ 4.33/ 8.00 1735ms total, 11527.38 ops/sec
LRANGE 100, 200/5 min/max/avg/p95: 3/ 45/ 18.99/ 30.00 1906ms total, 10493.18 ops/sec
LRANGE 100, 20000/5 min/max/avg/p95: 668/2226/1713.18/2147.00 2478ms total, 8071.03 ops/sec
End of tests.
```

for loops (5217 ms test.js):

```
Client count: 5, node version: 0.6.12, server version: 2.4.8, parser: hiredis
PING, 1/5 min/max/avg/p95: 0/ 8/ 0.11/ 1.00 2188ms total, 9140.77 ops/sec
PING, 50/5 min/max/avg/p95: 0/ 17/ 1.95/ 4.00 785ms total, 25477.71 ops/sec
PING, 200/5 min/max/avg/p95: 1/ 25/ 6.69/ 11.00 678ms total, 29498.53 ops/sec
PING, 20000/5 min/max/avg/p95: 52/ 600/ 319.67/ 552.55 621ms total, 32206.12 ops/sec
SET small str, 1/5 min/max/avg/p95: 0/ 19/ 0.11/ 1.00 2188ms total, 9140.77 ops/sec
SET small str, 50/5 min/max/avg/p95: 0/ 26/ 1.75/ 3.00 700ms total, 28571.43 ops/sec
SET small str, 200/5 min/max/avg/p95: 0/ 18/ 6.49/ 11.00 652ms total, 30674.85 ops/sec
SET small str, 20000/5 min/max/avg/p95: 49/ 669/ 358.86/ 626.55 679ms total, 29455.08 ops/sec
SET small buf, 1/5 min/max/avg/p95: 0/ 18/ 0.17/ 1.00 3416ms total, 5854.80 ops/sec
SET small buf, 50/5 min/max/avg/p95: 1/ 26/ 5.49/ 10.00 2199ms total, 9095.04 ops/sec
SET small buf, 200/5 min/max/avg/p95: 1/ 55/ 20.76/ 33.00 2085ms total, 9592.33 ops/sec
SET small buf, 20000/5 min/max/avg/p95: 194/2166/1216.54/2049.55 2176ms total, 9191.18 ops/sec
GET small str, 1/5 min/max/avg/p95: 0/ 5/ 0.10/ 1.00 2160ms total, 9259.26 ops/sec
GET small str, 50/5 min/max/avg/p95: 0/ 29/ 1.80/ 3.00 722ms total, 27700.83 ops/sec
GET small str, 200/5 min/max/avg/p95: 0/ 41/ 6.74/ 11.00 678ms total, 29498.53 ops/sec
GET small str, 20000/5 min/max/avg/p95: 54/ 635/ 340.72/ 584.55 646ms total, 30959.75 ops/sec
GET small buf, 1/5 min/max/avg/p95: 0/ 5/ 0.10/ 1.00 2155ms total, 9280.74 ops/sec
GET small buf, 50/5 min/max/avg/p95: 0/ 23/ 1.75/ 3.00 703ms total, 28449.50 ops/sec
GET small buf, 200/5 min/max/avg/p95: 0/ 32/ 6.57/ 10.00 660ms total, 30303.03 ops/sec
GET small buf, 20000/5 min/max/avg/p95: 50/ 644/ 357.94/ 601.00 654ms total, 30581.04 ops/sec
SET large str, 1/5 min/max/avg/p95: 0/ 30/ 0.14/ 1.00 2891ms total, 6918.02 ops/sec
SET large str, 50/5 min/max/avg/p95: 0/ 29/ 3.36/ 6.00 1347ms total, 14847.81 ops/sec
SET large str, 200/5 min/max/avg/p95: 0/ 65/ 13.60/ 35.55 1368ms total, 14619.88 ops/sec
SET large str, 20000/5 min/max/avg/p95: 176/1743/1051.82/1640.10 1835ms total, 10899.18 ops/sec
SET large buf, 1/5 min/max/avg/p95: 0/ 42/ 0.18/ 1.00 3722ms total, 5373.46 ops/sec
SET large buf, 50/5 min/max/avg/p95: 1/ 31/ 5.25/ 8.00 2103ms total, 9510.22 ops/sec
SET large buf, 200/5 min/max/avg/p95: 1/ 53/ 20.40/ 33.00 2049ms total, 9760.86 ops/sec
SET large buf, 20000/5 min/max/avg/p95: 404/2617/1550.55/2492.55 2626ms total, 7616.15 ops/sec
GET large str, 1/5 min/max/avg/p95: 0/ 29/ 0.12/ 1.00 2448ms total, 8169.93 ops/sec
GET large str, 50/5 min/max/avg/p95: 0/ 16/ 2.44/ 4.00 978ms total, 20449.90 ops/sec
GET large str, 200/5 min/max/avg/p95: 0/ 41/ 9.63/ 21.00 966ms total, 20703.93 ops/sec
GET large str, 20000/5 min/max/avg/p95: 341/ 773/ 560.95/ 735.55 1063ms total, 18814.68 ops/sec
GET large buf, 1/5 min/max/avg/p95: 0/ 12/ 0.11/ 1.00 2354ms total, 8496.18 ops/sec
GET large buf, 50/5 min/max/avg/p95: 0/ 18/ 2.45/ 4.00 980ms total, 20408.16 ops/sec
GET large buf, 200/5 min/max/avg/p95: 0/ 53/ 10.61/ 24.00 1065ms total, 18779.34 ops/sec
GET large buf, 20000/5 min/max/avg/p95: 293/ 723/ 548.55/ 699.00 1053ms total, 18993.35 ops/sec
INCR, 1/5 min/max/avg/p95: 0/ 17/ 0.10/ 1.00 2117ms total, 9447.33 ops/sec
INCR, 50/5 min/max/avg/p95: 0/ 23/ 1.67/ 3.00 669ms total, 29895.37 ops/sec
INCR, 200/5 min/max/avg/p95: 0/ 17/ 6.28/ 10.00 630ms total, 31746.03 ops/sec
INCR, 20000/5 min/max/avg/p95: 51/ 604/ 335.57/ 559.55 614ms total, 32573.29 ops/sec
LPUSH, 1/5 min/max/avg/p95: 0/ 20/ 0.10/ 1.00 2116ms total, 9451.80 ops/sec
LPUSH, 50/5 min/max/avg/p95: 0/ 25/ 1.70/ 3.00 681ms total, 29368.58 ops/sec
LPUSH, 200/5 min/max/avg/p95: 1/ 31/ 6.43/ 10.00 646ms total, 30959.75 ops/sec
LPUSH, 20000/5 min/max/avg/p95: 49/ 646/ 364.86/ 598.00 657ms total, 30441.40 ops/sec
LRANGE 10, 1/5 min/max/avg/p95: 0/ 5/ 0.12/ 1.00 2455ms total, 8146.64 ops/sec
LRANGE 10, 50/5 min/max/avg/p95: 0/ 23/ 2.00/ 3.00 801ms total, 24968.79 ops/sec
LRANGE 10, 200/5 min/max/avg/p95: 1/ 29/ 7.39/ 12.00 742ms total, 26954.18 ops/sec
LRANGE 10, 20000/5 min/max/avg/p95: 62/ 727/ 396.63/ 665.00 748ms total, 26737.97 ops/sec
LRANGE 100, 1/5 min/max/avg/p95: 0/ 22/ 0.20/ 1.00 4056ms total, 4930.97 ops/sec
LRANGE 100, 50/5 min/max/avg/p95: 0/ 28/ 4.57/ 8.00 1831ms total, 10922.99 ops/sec
LRANGE 100, 200/5 min/max/avg/p95: 2/ 55/ 20.34/ 34.00 2040ms total, 9803.92 ops/sec
LRANGE 100, 20000/5 min/max/avg/p95: 767/2185/1610.75/2060.55 2395ms total, 8350.73 ops/sec
End of tests.
```