Skip to content

Instantly share code, notes, and snippets.

@richmarr
Created November 5, 2013 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richmarr/7317039 to your computer and use it in GitHub Desktop.
Save richmarr/7317039 to your computer and use it in GitHub Desktop.
Quick Node.js speed test for different crypto algorithms exposed through OpenSSL. Don't forget, speed == good but speed !== good
var crypto = require('crypto'),
algos = crypto.getCiphers(),
testString = 'something to match, something to match, something to match, something to match, something to match '+algos.join("#"),
password = '12345asdfgh',
ciphertextEncoding = 'binary',
cleartextEncoding = 'utf8',
iterations = 1000;
algos.forEach(function( algorithm ){
var start = new Date().getTime(),
i;
try {
for ( i = 0; i < iterations; i++ ){
var cipher = crypto.createCipher( algorithm, password );
var encrypted = cipher.update( testString, cleartextEncoding, ciphertextEncoding );
encrypted += cipher.final( ciphertextEncoding );
var decipher = crypto.createDecipher( algorithm, password );
var decrypted = decipher.update( encrypted, ciphertextEncoding, cleartextEncoding );
decrypted += decipher.final( cleartextEncoding );
if ( decrypted !== testString ) throw new Error("match failed for "+algorithm);
}
console.log(algorithm,"did",i,"iterations in",new Date().getTime()-start,"ms");
} catch(e){
console.log(algorithm,e);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment