browserify / sha.js

Streamable SHA hashes in pure javascript
Other
288 stars 60 forks source link

Improve sha* code structuring consistency #17

Closed dcousens closed 9 years ago

dcousens commented 9 years ago

This pull request cleans up each of the sha*.js modules so that they are as consistent as possible. In doing this, some dead code was removed including the removal of code that were artifacts of the original implementations.

dominictarr commented 9 years ago

okay this looks good, but we need to run it through https://github.com/dominictarr/crypto-bench to make sure this is not a performance regression.

dcousens commented 9 years ago

Sounds good :+1: , I'll do that tonight

dcousens commented 9 years ago

@dominictarr

this pull request

run (N), input-size (bytes), ops (bytes/ms), time (ms)
1, 1, 36.29, 0.02755580049600441
3, 2, 100.2, 0.01996007984031936
5, 3, 151.68, 0.01977848101265823
7, 4, 184.96, 0.02162629757785467
8, 5, 231.45, 0.02160293799956794
9, 6, 278.34, 0.02155636990730761
10, 7, 272.72, 0.02566735112936345
11, 9, 323.37, 0.027831895352073477
12, 11, 443.85, 0.024783147459727387
13, 14, 590.24, 0.023719165085388995
14, 17, 715.7, 0.023752969121140142
15, 21, 877.17, 0.023940627244433806
16, 25, 1078.75, 0.023174971031286212
17, 31, 1417.01, 0.021877050973528767
18, 38, 1509.74, 0.025169896803423106
19, 46, 1984.44, 0.023180343069077423
20, 56, 1360.24, 0.04116920543433512
21, 69, 1822.98, 0.03785011355034065
22, 84, 2227.68, 0.03770739064856712
23, 103, 2747.01, 0.03749531308586427
24, 126, 2371.32, 0.053134962805526036
25, 154, 3314.08, 0.046468401486988845
26, 188, 2776.76, 0.06770480704129993
27, 230, 3532.8, 0.06510416666666667
28, 282, 3183.78, 0.08857395925597875
29, 345, 2994.6, 0.1152073732718894
30, 422, 4127.16, 0.10224948875255624
31, 516, 3049.56, 0.1692047377326565
32, 631, 3539.91, 0.17825311942959002
33, 772, 3396.8, 0.22727272727272727
34, 944, 3596.64, 0.26246719160104987
35, 1155, 3753.75, 0.3076923076923077
36, 1413, 3730.32, 0.3787878787878788
37, 1728, 3646.08, 0.47393364928909953
38, 2113, 3634.36, 0.5813953488372093
39, 2585, 3438.05, 0.7518796992481203
40, 3162, 3984.12, 0.7936507936507936
41, 3868, 3365.16, 1.1494252873563218
42, 4732, 3880.24, 1.2195121951219512
43, 5788, 4068.792079207921, 1.4225352112676057
44, 7079, 3995.079207920792, 1.7719298245614035
45, 8660, 4330, 2
46, 10593, 3985.4851485148515, 2.6578947368421053
47, 12957, 3556.823529411765, 3.642857142857143
48, 15849, 3539.097087378641, 4.478260869565218
49, 19387, 3263.158415841584, 5.9411764705882355
50, 23714, 4268.52, 5.555555555555555
51, 29007, 3981.3529411764707, 7.285714285714286
52, 35481, 4133.708737864078, 8.583333333333334
53, 43401, 3437.70297029703, 12.625
54, 53088, 3932.4444444444443, 13.5
55, 64938, 3819.8823529411766, 17
56, 79433, 4108.603448275862, 19.333333333333332
57, 97163, 3379.582608695652, 28.75
58, 118850, 4442.990654205608, 26.75
59, 145378, 4578.834645669292, 31.75
60, 177828, 4521.050847457627, 39.333333333333336
61, 217520, 4531.666666666667, 48
62, 266073, 3644.8356164383563, 73
63, 325462, 3159.8252427184466, 103
64, 398107, 4629.1511627906975, 86
65, 486968, 3689.151515151515, 132
66, 595662, 4412.311111111111, 135
67, 728618, 4582.503144654088, 159
68, 891251, 4570.5179487179485, 195
69, 1090184, 4360.736, 250
70, 1333521, 4614.259515570934, 289
71, 1631173, 4594.853521126761, 355
72, 1995262, 4503.977426636568, 443
73, 2440619, 4587.62969924812, 532
74, 2985383, 4628.500775193798, 645
75, 3651741, 4564.67625, 800
76, 4466836, 4539.467479674797, 984
77, 5463865, 4471.2479541734865, 1222
78, 6683439, 4521.947902571042, 1478
79, 8175230, 4506.742006615215, 1814
80, 10000000, 4522.840343735867, 2211

npm install sha.js

run (N), input-size (bytes), ops (bytes/ms), time (ms)
1, 1, 31.79, 0.031456432840515886
3, 2, 97, 0.020618556701030927
5, 3, 138.48, 0.021663778162911613
7, 4, 187.04, 0.0213857998289136
8, 5, 233.6, 0.021404109589041095
9, 6, 247.38, 0.02425418384671356
10, 7, 299.25, 0.023391812865497075
11, 9, 398.16, 0.022603978300180832
12, 11, 477.95, 0.023014959723820484
13, 14, 639.66, 0.02188662727073758
14, 17, 720.8, 0.02358490566037736
15, 21, 860.58, 0.02440214738897023
16, 25, 1170, 0.021367521367521368
17, 31, 1518.07, 0.020420665713702265
18, 38, 1821.34, 0.020863759649488837
19, 46, 1966.5, 0.023391812865497075
20, 56, 1570.24, 0.03566333808844508
21, 69, 1937.52, 0.03561253561253561
22, 84, 2355.36, 0.03566333808844508
23, 103, 2877.82, 0.03579098067287044
24, 126, 2546.46, 0.04948045522018803
25, 154, 2557.94, 0.060204695966285374
26, 188, 2874.52, 0.06540222367560497
27, 230, 3337.3, 0.06891798759476224
28, 282, 3460.14, 0.08149959250203749
29, 345, 3753.6, 0.09191176470588236
30, 422, 3435.08, 0.12285012285012285
31, 516, 3524.28, 0.14641288433382138
32, 631, 3905.89, 0.16155088852988692
33, 772, 3690.16, 0.20920502092050208
34, 944, 3747.68, 0.2518891687657431
35, 1155, 3950.1, 0.29239766081871343
36, 1413, 3956.4, 0.35714285714285715
37, 1728, 3905.28, 0.4424778761061947
38, 2113, 3655.49, 0.5780346820809249
39, 2585, 4187.7, 0.6172839506172839
40, 3162, 3604.68, 0.8771929824561403
41, 3868, 3558.56, 1.0869565217391304
42, 4732, 4306.12, 1.098901098901099
43, 5788, 4109.48, 1.408450704225352
44, 7079, 4345.524752475248, 1.6290322580645162
45, 8660, 4156.8, 2.0833333333333335
46, 10593, 3707.55, 2.857142857142857
47, 12957, 4016.67, 3.225806451612903
48, 15849, 3077.4757281553398, 5.15
49, 19387, 4329.135922330097, 4.478260869565218
50, 23714, 4184.823529411765, 5.666666666666667
51, 29007, 4060.98, 7.142857142857143
52, 35481, 3647.5794392523367, 9.727272727272727
53, 43401, 3792.3203883495144, 11.444444444444445
54, 53088, 3932.4444444444443, 13.5
55, 64938, 4329.2, 15
56, 79433, 3115.0196078431372, 25.5
57, 97163, 3737.0384615384614, 26
58, 118850, 4244.642857142857, 28
59, 145378, 3489.072, 41.666666666666664
60, 177828, 3419.769230769231, 52
61, 217520, 3425.511811023622, 63.5
62, 266073, 4471.81512605042, 59.5
63, 325462, 4458.3835616438355, 73
64, 398107, 4498.38418079096, 88.5
65, 486968, 3478.342857142857, 140
66, 595662, 3610.072727272727, 165
67, 728618, 3814.753926701571, 191
68, 891251, 3667.6995884773664, 243
69, 1090184, 4008.029411764706, 272
70, 1333521, 4115.805555555556, 324
71, 1631173, 4161.155612244898, 392
72, 1995262, 4218.31289640592, 473
73, 2440619, 4259.3699825479935, 573
74, 2985383, 4326.642028985507, 690
75, 3651741, 4342.141498216409, 841
76, 4466836, 4534.858883248731, 985
77, 5463865, 4460.297959183674, 1225
78, 6683439, 4525.009478672986, 1477
79, 8175230, 4524.200332042059, 1807
80, 10000000, 4514.6726862302485, 2215
dcousens commented 9 years ago

Conclusion: In terms of performance, for lower input sizes, there exists a small margin of improvement, however, for larger input sizes that margin is not significant.

dominictarr commented 9 years ago

am I statisified. merging.

dominictarr commented 9 years ago

merged into 2.3.2