Computing file hashes with node.js
saltwaterc.eu
saltwaterc.eu
7 fs.readFile(filename, function (err, data) {
8 shasum.update(data);
9 console.log(shasum.digest('hex') + ' ' + filename);
10 });
Here are the results: $ dd if=/dev/urandom of=xxx.data bs=1000 count=200000
$ time sha256sum xxx.data
e774e4c46ab832ec09dbfd1a944044651560c3fdc3c5e2e8b46c2ea7d54f6649 xxx.data
real 0m2.087s
user 0m2.000s
sys 0m0.064s
$ time node xxx-1.js xxx.data
e774e4c46ab832ec09dbfd1a944044651560c3fdc3c5e2e8b46c2ea7d54f 6649 xxx.data
4883
real 0m13.972s
user 0m13.885s
sys 0m0.264s
$ time node xxx-2.js xxx.data
e774e4c46ab832ec09dbfd1a944044651560c3fdc3c5e2e8b46c2ea7d54f6649 xxx.data
real 0m14.043s
user 0m13.433s
sys 0m0.732s
Personally I never make multiple calls to update() but it seems not to be linked here. Oh, and check the docs, readFile() is async.PS: timings of xxx-1.js and xxx-2.js are equivalent on several runs.
No doubt its useful information but when presented like this the effect is diluted.
Updated the article as well. I usually post all the output to avoid the appearance that I made up the results. Even though they are fully reproducible up to an extent. Or that I have better things to do that making up horror stories about poor node.js performances in certain areas.
Seriously folks...