Skip to content

Commit

Permalink
suite: benchmark.py get disasm code from binary file (python itself) …
Browse files Browse the repository at this point in the history
…rather than randomize data - this stablizes results, and can be compared with other bindings
  • Loading branch information
aquynh committed Jan 13, 2014
1 parent e14556a commit 34474f8
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions suite/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,42 @@
from random import randint


def random_str(size):
lst = [str(randint(0, 255)) for _ in xrange(size)]
return "".join(lst)
# file providing code to disassemble
FILE = '/usr/bin/python'

def cs(md, data):
insns = md.disasm(data, 0)

def get_code(f, size):
code = f.read(size)
if len(code) != size: # reached end-of-file?
f.seek(0)
code = f.read(size)

return code


def cs(md, code):
insns = md.disasm(code, 0)
# uncomment below line to speed up this function 200 times!
# return
for i in insns:
if i.address == 0x100000:
print i


md = Cs(CS_ARCH_X86, CS_MODE_32)
md.detail = False

cfile = open(FILE)

# warm up few times
for i in xrange(3):
data = random_str(128)
cs(md, data)
code = get_code(cfile, 128)
cs(md, code)

# start real benchmark
c_t = 0
for i in xrange(10000):
code = random_str(128)
code = get_code(cfile, 128)

t1 = time()
cs(md, code)
Expand Down

0 comments on commit 34474f8

Please sign in to comment.