Skip to content

Commit 6de6af0

Browse files
committed
speedtest.py: Make it workable with different Python versions
1 parent 80e5f64 commit 6de6af0

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

speedtest.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
#!/usr/bin/env python
2-
from libinjection import *
1+
#!/usr/bin/env python3
2+
from libinjection import sqli_state
33
from words import *
44
import time
5+
import sys
6+
if sys.version_info > (3, 7):
7+
from time import process_time as clock
8+
else:
9+
from time import clock as clock
510

611
def lookup_null(state, style, keyword):
712
return ''
@@ -29,58 +34,58 @@ def main():
2934
)
3035
imax = 100000
3136

32-
t0 = time.clock()
37+
t0 = clock()
3338
sfilter = sqli_state()
3439
for i in xrange(imax):
3540
s = inputs[i % 7]
3641
sqli_init(sfilter, s, 0)
3742
is_sqli(sfilter)
38-
t1 = time.clock()
43+
t1 = clock()
3944
total = imax / (t1 - t0)
4045
print("python->c TPS = {0}".format(total))
4146

42-
t0 = time.clock()
47+
t0 = clock()
4348
sfilter = sqli_state()
4449
for i in xrange(imax):
4550
s = inputs[i % 7]
4651
sqli_init(sfilter, s, 0)
4752
sqli_callback(sfilter, lookup_null)
4853
is_sqli(sfilter)
49-
t1 = time.clock()
54+
t1 = clock()
5055
total = imax / (t1 - t0)
5156
print("python lookup_null TPS = {0}".format(total))
5257

53-
t0 = time.clock()
58+
t0 = clock()
5459
sfilter = sqli_state()
5560
for i in xrange(imax):
5661
s = inputs[i % 7]
5762
sqli_init(sfilter, s, 0)
5863
sqli_callback(sfilter, lookup_upcase)
5964
is_sqli(sfilter)
60-
t1 = time.clock()
65+
t1 = clock()
6166
total = imax / (t1 - t0)
6267
print("python lookup_upcase TPS = {0}".format(total))
6368

64-
t0 = time.clock()
69+
t0 = clock()
6570
sfilter = sqli_state()
6671
for i in xrange(imax):
6772
s = inputs[i % 7]
6873
sqli_init(sfilter, s, 0)
6974
sqli_callback(sfilter, lookup_c)
7075
is_sqli(sfilter)
71-
t1 = time.clock()
76+
t1 = clock()
7277
total = imax / (t1 - t0)
7378
print("python lookup_c TPS = {0}".format(total))
7479

7580

76-
t0 = time.clock()
81+
t0 = clock()
7782
sfilter = sqli_state()
7883
for i in xrange(imax):
7984
s = inputs[i % 7]
8085
sqli_init(sfilter, s, 0)
8186
sqli_callback(sfilter, lookup)
8287
is_sqli(sfilter)
83-
t1 = time.clock()
88+
t1 = clock()
8489
total = imax / (t1 - t0)
8590
print("python lookup TPS = {0}".format(total))
8691

0 commit comments

Comments
 (0)