Skip to content

Commit

Permalink
suite: benchmark.py can benchmark specific archs, rather than all arc…
Browse files Browse the repository at this point in the history
…hs like before
  • Loading branch information
aquynh committed Jan 13, 2014
1 parent 783e6c0 commit f48a879
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions suite/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
#!/usr/bin/python

# Simple benchmark for Capstone by disassembling random code. By Nguyen Anh Quynh, 2014
# Syntax:
# ./suite/benchmark.py --> Benchmark all archs
# ./suite/benchmark.py x86 --> Benchmark all X86 (all 16bit, 32bit, 64bit)
# ./suite/benchmark.py x86-32 --> Benchmark X86-32 arch only
# ./suite/benchmark.py arm --> Benchmark all ARM (arm, thumb)
# ./suite/benchmark.py aarch64 --> Benchmark ARM-64
# ./suite/benchmark.py mips --> Benchmark all Mips (32bit, 64bit)
# ./suite/benchmark.py ppc --> Benchmark PPC

from capstone import *

from time import time
from random import randint
import sys


# file providing code to disassemble
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_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_ARM, CS_MODE_THUMB, "THUMB (ARM)", 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_ARM64, CS_MODE_ARM, "ARM-64 (AArch64)", 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),
)
Expand Down Expand Up @@ -52,6 +61,13 @@ def cs(md, code):
cfile = open(FILE)

for (arch, mode, comment, syntax) in all_tests:
try:
request = sys.argv[1]
if not request in comment.lower():
continue
except:
pass

print("Platform: %s" %comment)

try:
Expand Down

0 comments on commit f48a879

Please sign in to comment.