Skip to content

Instantly share code, notes, and snippets.

@jay3sh
Created April 9, 2014 16:23
Show Gist options
  • Select an option

  • Save jay3sh/10288621 to your computer and use it in GitHub Desktop.

Select an option

Save jay3sh/10288621 to your computer and use it in GitHub Desktop.

Revisions

  1. jay3sh created this gist Apr 9, 2014.
    32 changes: 32 additions & 0 deletions cryptotest.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    var crypto = require('crypto');

    function run(algo) {
    var hash = crypto.createHash(algo);
    hash.update('operation');
    hash.update('1');
    hash.update('A34');
    hash.update('ABS');

    return hash.digest('hex');
    }

    function loop(algo) {
    var start = new Date().getTime();
    for(var i=0; i<1000000; i++) {
    run(algo);
    }
    var end = new Date().getTime();
    return end-start;
    }

    console.log('md5',run('md5').length, loop('md5'));
    console.log('sha1',run('sha1').length, loop('sha1'));
    console.log('sha256',run('sha256').length, loop('sha256'));

    /*
    Output of sample run (times in millisecond)
    md5 32 2810
    sha1 40 2954
    sha256 64 3311
    */