Skip to content

Instantly share code, notes, and snippets.

@Madh93
Created June 10, 2016 21:23
Show Gist options
  • Save Madh93/b15b743d1a8fbbe7b7d5d47028673a17 to your computer and use it in GitHub Desktop.
Save Madh93/b15b743d1a8fbbe7b7d5d47028673a17 to your computer and use it in GitHub Desktop.
MD5 Test
var crypto = require('crypto');
start_time = new Date();
var c = 0;
var m = 10000000;
while (c < m) {
var n0 = Math.floor(Math.random() * 9999999999);
var n1 = Math.floor(Math.random() * 9999999999);
var nn = crypto.createHash('md5').update(n0.toString()+n1.toString()).digest("hex");
c++;
}
console.log("Node version: " + process.version);
console.log("Execution time (seconds): " + ((new Date() - start_time)/1000);
from random import randint
import sys, time, hashlib
startTime = time.time()
c=0
m=10000000
while(c<m):
n0=randint(0,9999999999)
n1=randint(0,9999999999)
nn=hashlib.md5((str(n0) + str(n1)).encode('utf-8')).hexdigest()
c=c+1
print ('Python: Version ' + sys.version)
print ('Execution time: {0}'.format(time.time() - startTime))
require 'digest'
start_time = Time.now
c = 0
m = 10000000
while c < m
n0 = rand(9999999999)
n1 = rand(9999999999)
nn = Digest::MD5.hexdigest(n0.to_s << n1.to_s)
c += 1
end
puts "Ruby version: #{RUBY_VERSION}"
puts "Execution time: #{Time.now - start_time}"
#! /bin/bash
python md5test.py > results.txt
echo "-----" >> results.txt
node md5test.js >> results.txt
echo "-----" >> results.txt
ruby md5test.rb >> results.txt
Python version: 3.5.1
Execution time (seconds): 39.753
-----
Node version: 6.2.1
Execution time (seconds): 19.281
-----
Ruby version: 2.3.1
Execution time (seconds): 13.836
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment