Skip to content

Instantly share code, notes, and snippets.

@scottopell
Created February 25, 2018 16:40
Show Gist options
  • Save scottopell/e6aaaea5835a01fab1e63fe4a56898d6 to your computer and use it in GitHub Desktop.
Save scottopell/e6aaaea5835a01fab1e63fe4a56898d6 to your computer and use it in GitHub Desktop.
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var createHash = require('crypto').createHash;
suite.add('md2', () => {
createHash('md2').update('HELLO WORLD').digest('hex');
})
.add('md4', () => {
createHash('md4').update('HELLO WORLD').digest('hex');
})
.add('md5', () => {
createHash('md5').update('HELLO WORLD').digest('hex');
})
.add('mdc2', () => {
createHash('mdc2').update('HELLO WORLD').digest('hex');
})
.add('rmd160', () => {
createHash('rmd160').update('HELLO WORLD').digest('hex');
})
.add('sha', () => {
createHash('sha').update('HELLO WORLD').digest('hex');
})
.add('sha1', () => {
createHash('sha1').update('HELLO WORLD').digest('hex');
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ 'async': true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment