-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_hash_compare.py
More file actions
98 lines (93 loc) · 2.22 KB
/
python_hash_compare.py
File metadata and controls
98 lines (93 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'''
Script for comparing the speed of Python's various hashing functions.
@author: Chris Jarabek chris.jarabek@gmail.com
'''
import random, hashlib, time, os
total_time = 0
print "MD5"
print "---------------"
hashlib.md5("").hexdigest()
for i in range(10):
blob = ''
for j in range(1024 * 1024):
blob += chr(random.randint(0, 255))
path = './tmp.dat'
f = open(path, 'w')
f.write(blob)
f.close
data_bytes = open(path, 'rb').read()
start = time.time()
hashlib.md5(data_bytes).hexdigest()
end = time.time()
diff = (end - start)
total_time += diff
print diff
print "Average: "
md5avg = total_time / 10
print md5avg
print "SHA1"
print "---------------"
hashlib.sha1("").hexdigest()
total_time = 0
for i in range(10):
blob = ''
for j in range(1024 * 1024):
blob += chr(random.randint(0, 255))
path = './tmp.dat'
f = open(path, 'w')
f.write(blob)
f.close
data_bytes = open(path, 'rb').read()
start = time.time()
hashlib.sha1(data_bytes).hexdigest()
end = time.time()
diff = (end - start)
total_time += diff
print diff
print "Average: "
sha1avg = total_time / 10
print sha1avg
print "SHA256"
print "---------------"
hashlib.sha256("").hexdigest()
total_time = 0
for i in range(10):
blob = ''
for j in range(1024 * 1024):
blob += chr(random.randint(0, 255))
path = './tmp.dat'
f = open(path, 'w')
f.write(blob)
f.close
data_bytes = open(path, 'rb').read()
start = time.time()
hashlib.sha256(data_bytes).hexdigest()
end = time.time()
diff = (end - start)
total_time += diff
print diff
print "Average: "
sha256avg = total_time / 10
print sha256avg
print "SHA512"
print "---------------"
hashlib.sha512("").hexdigest()
total_time = 0
for i in range(10):
blob = ''
for j in range(1024 * 1024):
blob += chr(random.randint(0, 255))
path = './tmp.dat'
f = open(path, 'w')
f.write(blob)
f.close
data_bytes = open(path, 'rb').read()
start = time.time()
hashlib.sha512(data_bytes).hexdigest()
end = time.time()
diff = (end - start)
total_time += diff
print diff
print "Average: "
sha512avg = total_time / 10
print sha512avg