Created
January 5, 2015 22:21
-
-
Save Kagami/883856830a884fe22541 to your computer and use it in GitHub Desktop.
SHA-512: sha.js vs hash.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmarking: SHA-512 | |
sha.js#SHA-512 x 101,383 ops/sec ±0.45% (42 runs sampled) | |
hash.js#SHA-512 x 24,485 ops/sec ±0.19% (43 runs sampled) | |
------------------------ | |
Fastest is sha.js#SHA-512 | |
======================== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmarking: SHA-512 | |
sha.js#SHA-512 x 52,135 ops/sec ±0.68% (41 runs sampled) | |
hash.js#SHA-512 x 4,880 ops/sec ±0.87% (43 runs sampled) | |
------------------------ | |
Fastest is sha.js#SHA-512 | |
======================== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmarking: SHA-512 | |
sha.js#SHA-512 x 16,779 ops/sec ±10.90% (56 runs sampled) | |
hash.js#SHA-512 x 10,781 ops/sec ±1.87% (62 runs sampled) | |
------------------------ | |
Fastest is sha.js#SHA-512 | |
======================== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var benchmark = require("benchmark"); | |
var shajsCreateHash = require("sha.js"); | |
var hashjsSha512 = require("hash.js").sha512; | |
var benchmarks = []; | |
var maxTime = 3; | |
function add(op, obj) { | |
benchmarks.push(function() { | |
var suite = new benchmark.Suite(); | |
Object.keys(obj).forEach(function(key) { | |
suite.add(key + "#" + op, obj[key], {maxTime: maxTime}) | |
}); | |
return suite | |
.on("start", function() { | |
console.log("Benchmarking: " + op); | |
}) | |
.on("cycle", function(event) { | |
console.log(String(event.target)); | |
}) | |
.on("complete", function() { | |
console.log("------------------------"); | |
console.log("Fastest is " + this.filter("fastest").pluck("name")); | |
console.log("========================"); | |
}) | |
.run(); | |
}); | |
} | |
function start() { | |
var bstart = benchmarks.shift(); | |
if (bstart) { | |
bstart().on("complete", start); | |
} | |
} | |
var msg = new Buffer("test"); | |
add("SHA-512", { | |
"sha.js": function() { | |
return shajsCreateHash("sha512").update(msg).digest(); | |
}, | |
"hash.js": function() { | |
return hashjsSha512().update(msg).digest(); | |
}, | |
}); | |
start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50 | |
sha.js: SHA-512*5000: 183.340ms | |
af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50 | |
hash.js: SHA-512*5000: 556.064ms | |
af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50 | |
sha.js: SHA-512*5000: 148.775ms | |
af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50 | |
hash.js: SHA-512*5000: 537.490ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sha.js: SHA-512*5000: timer started | |
"af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50" | |
sha.js: SHA-512*5000: 238.05ms | |
hash.js: SHA-512*5000: timer started | |
"af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50" | |
hash.js: SHA-512*5000: 2216.61ms | |
sha.js: SHA-512*5000: timer started | |
"af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50" | |
sha.js: SHA-512*5000: 234.75ms | |
hash.js: SHA-512*5000: timer started | |
"af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50" | |
hash.js: SHA-512*5000: 2223.09ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50 | |
sha.js: SHA-512*5000: 654ms | |
af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50 | |
hash.js: SHA-512*5000: 1054ms | |
af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50 | |
sha.js: SHA-512*5000: 610ms | |
af59f0802401edfd3425ef4f6af2a2ccb1bb8b7ddba2757cd379d7c03459c895b3019b73cbf45e715ef083d679b8c055022febff06af3d86cae84a56170f9a50 | |
hash.js: SHA-512*5000: 1017ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var shajsCreateHash = require("sha.js"); | |
var hashjsSha512 = require("hash.js").sha512; | |
var N = 5000; | |
var initialHash = new Buffer("test"); | |
function shajsChainHashing(buf) { | |
function digest(buf) { | |
return shajsCreateHash("sha512").update(buf).digest(); | |
}; | |
var i; | |
for (i = 0; i < N; ++i) { | |
buf = digest(digest(buf)); | |
} | |
return buf.toString("hex"); | |
} | |
function hashjsChainHashing(buf) { | |
function digest(buf) { | |
return hashjsSha512().update(buf).digest(); | |
}; | |
var i; | |
for (i = 0; i < N; ++i) { | |
buf = digest(digest(buf)); | |
} | |
return new Buffer(buf).toString("hex"); | |
} | |
console.time("sha.js: SHA-512*"+N); | |
console.log(shajsChainHashing(initialHash)); | |
console.timeEnd("sha.js: SHA-512*"+N); | |
console.time("hash.js: SHA-512*"+N); | |
console.log(hashjsChainHashing(initialHash)); | |
console.timeEnd("hash.js: SHA-512*"+N); | |
console.time("sha.js: SHA-512*"+N); | |
console.log(shajsChainHashing(initialHash)); | |
console.timeEnd("sha.js: SHA-512*"+N); | |
console.time("hash.js: SHA-512*"+N); | |
console.log(hashjsChainHashing(initialHash)); | |
console.timeEnd("hash.js: SHA-512*"+N); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment