HaneCa

独り立ちへ向けた長い道

アルゴリズム別ハッシュ値計算の処理時間(node.js)

投稿日: 2017年9月3日 最終更新日: 2018年1月4日

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);  
});

 

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください