南大通用GBase 8a支持sha256的sftp加载性能对比sha1下降情况

GBase 8a新版本支持了sha256,本文介绍从算法角度,sha256和sha1的性能差距。

结论

sha1和sha256从算法角度,性能下降在 20%。

复用UUID

generateStringToHash() with: return UUID_STRING

数据编码长度在 ~36 字符(f5cdcda7-d873-455f-9902-dc9c7894bee0). UUID复用了。

Hash#1 (ms)#2 (ms)#3 (ms)#4 (ms)#5 (ms)Average per 1M (ms)
MD5649623621624620627.4
SHA-1608588630600594604
SHA-256746724741720758737.8
SHA-512107310551050105210521056.4

复用UUID+时间戳

generateStringToHash() with: return UUID_STRING + System.currentTimeMillis();

数据编码长度 ~49 字符(aa096640-21d6-4f44-9c49-4115d3fa69381468217419114). 包括了时间戳。UUID复用了。

Hash#1 (ms)#2 (ms)#3 (ms)#4 (ms)#5 (ms)Average per 1M (ms)
MD5751789745806737765.6
SHA-1768765694763751748.2
SHA-256842876848839850851
SHA-512116111521164115411631158.8

计算UUID+时间戳

generateStringToHash() with: return UUID.randomUUID().toString() + System.currentTimeMillis();

字符编码长度 ~49(1af4a3e1-1d92-40e7-8a74-7bb7394211e01468216765464). 每次重新计算UUID.

Hash#1 (ms)#2 (ms)#3 (ms)#4 (ms)#5 (ms)Average per 1M (ms)
MD51505 14711518146314871488.8
SHA-1133313091323132613341325
SHA-256150514961507149815161504.4
SHA-512183418271833183618571837.4

复用UUID+复用UUID

generateStringToHash() with: return UUID_STRING + UUID_STRING;

数据编码长度 ~72 字节(57149cb6-991c-4ffd-9c98-d823ee8a61f757149cb6-991c-4ffd-9c98-d823ee8a61f7)。

Hash#1 (ms)#2 (ms)#3 (ms)#4 (ms)#5 (ms)Average per 1M (ms)
MD5856824876811828839
SHA-1921896970904893916.8
SHA-256114511371241114111771168.2
SHA-512113311311116110211101118.4

复用UUID+复用UUID+时间戳

generateStringToHash() with: return UUID_STRING + UUID_STRING + System.currentTimeMillis();

数据编码长度 ~85字符 (759529c5-1f57-4167-b289-899c163c775e759529c5-1f57-4167-b289-899c163c775e1468218673060).

Hash#1 (ms)#2 (ms)#3 (ms)#4 (ms)#5 (ms)Average per 1M (ms)
MD5102910351034101210371029.4
SHA-110081016102710079901009.6
SHA-256125412491290125912481260
SHA-512122812211232123012261227.4

计算UUID+复用UUID+时间戳

generateStringToHash() with: final String randomUuid = UUID.randomUUID().toString();
return randomUuid + randomUuid + System.currentTimeMillis();

编码长度 ~85 字符(2734b31f-16db-4eba-afd5-121d0670ffa72734b31f-16db-4eba-afd5-121d0670ffa71468217683040). UUID每次重新产生,然后复用.

Hash#1 (ms)#2 (ms)#3 (ms)#4 (ms)#5 (ms)Average per 1M (ms)
MD5175317571739175116911738.2
SHA-1163416341627163416331632.4
SHA-256196219561988198819241963.6
SHA-512190919461936192918951923

参考

https://automationrhapsody.com/md5-sha-1-sha-256-sha-512-speed-performance/