From 783e6c006c434e2ab1843d2693fa357cacfef484 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Mon, 13 Jan 2014 15:55:12 +0800 Subject: [PATCH] suite: benchmark.py now exercises all archs --- suite/benchmark.py | 52 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/suite/benchmark.py b/suite/benchmark.py index 732a68341..ca0f7a5cd 100755 --- a/suite/benchmark.py +++ b/suite/benchmark.py @@ -12,9 +12,25 @@ from random import randint FILE = '/usr/bin/python' +all_tests = ( + (CS_ARCH_X86, CS_MODE_16, "X86 16bit (Intel syntax)", 0), + (CS_ARCH_X86, CS_MODE_32, "X86 32bit (ATT syntax)", CS_OPT_SYNTAX_ATT), + (CS_ARCH_X86, CS_MODE_32, "X86 32 (Intel syntax)", 0), + (CS_ARCH_X86, CS_MODE_64, "X86 64 (Intel syntax)", 0), + (CS_ARCH_ARM, CS_MODE_ARM, "ARM", 0), + (CS_ARCH_ARM, CS_MODE_THUMB, "THUMB-2", 0), + (CS_ARCH_MIPS, CS_MODE_32 + CS_MODE_BIG_ENDIAN, "MIPS-32 (Big-endian)", 0), + (CS_ARCH_MIPS, CS_MODE_64 + CS_MODE_LITTLE_ENDIAN, "MIPS-64-EL (Little-endian)", 0), + (CS_ARCH_ARM64, CS_MODE_ARM, "ARM-64", 0), + (CS_ARCH_PPC, CS_MODE_BIG_ENDIAN, "PPC-64", 0), + (CS_ARCH_PPC, CS_MODE_BIG_ENDIAN, "PPC-64, print register with number only", CS_OPT_SYNTAX_NOREGNAME), + ) + + def get_code(f, size): code = f.read(size) if len(code) != size: # reached end-of-file? + # then reset file position to begin-of-file f.seek(0) code = f.read(size) @@ -35,19 +51,31 @@ md.detail = False cfile = open(FILE) -# warm up few times -for i in xrange(3): - code = get_code(cfile, 128) - cs(md, code) +for (arch, mode, comment, syntax) in all_tests: + print("Platform: %s" %comment) -# start real benchmark -c_t = 0 -for i in xrange(50000): - code = get_code(cfile, 128) + try: + md = Cs(arch, mode) - t1 = time() - cs(md, code) - c_t += time() - t1 + if syntax != 0: + md.syntax = syntax + # warm up few times + cfile.seek(0) + for i in xrange(3): + code = get_code(cfile, 128) + cs(md, code) -print "Capstone:", c_t, "seconds" + # start real benchmark + c_t = 0 + for i in xrange(50000): + code = get_code(cfile, 128) + + t1 = time() + cs(md, code) + c_t += time() - t1 + + print "Benchmark:", c_t, "seconds" + print + except CsError as e: + print("ERROR: %s" %e)