node.jsでハッシュ値の計算時間を測定しました。md5, sha1, sha256, sha512で比較したところ、sha1が一番早い結果になりました。
測定環境:
- OS: Mac OSX 10.12.6
- Node.js: v8.4.0
- データサイズ: 2 x 1024 x 1024 x 1024 – 1 (約2GB)
測定結果:
アルゴリズム | 処理時間 (ms) |
md5 | 3970 |
sha1 | 2918 |
sha256 | 6058 |
sha512 | 4334 |
測定に利用したプログラム: (github)
const fs = require('fs'); const path = require('path'); const crypto = require('crypto'); function calculateHash(type, size) { const buf = Buffer.alloc(size, 1); const algorythm = crypto.createHash(type); let start = new Date(); algorythm.update(buf); algorythm.digest('hex'); let duration = new Date() - start; console.log(type + ': ' + duration + 'ms'); } let types = ['md5', 'sha1', 'sha256', 'sha512']; let size = 1024 * 1024 * 1024 * 2 - 1; types.forEach((type) => { calculateHash(type, size); });