accesstimer
author Paul Crowley <paul@ciphergoth.org>
Sun Dec 28 13:09:37 2008 +0000 (2008-12-28)
changeset 132 8f4d41d003e2
parent 53 001ab356ba3e
permissions -rwxr-xr-x
Save on reallocations
     1 #!/usr/bin/env python
     2 
     3 import sys
     4 
     5 sys.path.append("/home/paul/g/fetched/corepy-1.0")
     6 
     7 import time
     8 import array
     9 
    10 import corepy.arch.x86.platform as env
    11 import corepy.arch.x86.isa as x86
    12 import corepy.arch.x86.types.registers as r
    13 from corepy.arch.x86.lib.memory import MemRef
    14 from corepy.lib.extarray import extarray
    15 
    16 def timecmd(name, cmd, r):
    17     c = 0
    18     total = 0
    19     while total < 2:
    20         t = time.time()
    21         cmd()
    22         d = time.time()
    23         total += d - t
    24         c += 1
    25     print "%s %5.1f" % (name, total*(2.4E9)/(r*c))
    26 
    27 reps = (1<<6)
    28 
    29 code = env.InstructionStream()
    30 code.add(x86.nop())
    31 def callasm():
    32     for i in range(reps):
    33         params = env.ExecParams()
    34         env.Processor().execute(code)
    35 timecmd("callasm", callasm, reps)
    36 
    37 datasize = (1<<14)
    38 
    39 def timeaccess(name, items, mask, store):
    40     def timereps():
    41         for i in xrange(reps):
    42             for j in xrange(items):
    43                store[j] ^= mask
    44     timecmd(name, timereps, datasize*reps)
    45 
    46 timeaccess("snative", datasize>>2, 3, [0] * (datasize >> 2))
    47 timeaccess("native", datasize>>2, 0xffffffff, [0] * (datasize >> 2))
    48 timeaccess("sarray", datasize>>2, 3, array.array('L', [0] * (datasize >> 2)))
    49 timeaccess("array", datasize>>2, 0xfffffff, array.array('L', [0] * (datasize >> 2)))
    50 timeaccess("sulongs", datasize>>2, 3,  extarray('L', datasize >> 2))
    51 timeaccess("ulongs", datasize>>2, 0xffffffff,  extarray('L', datasize >> 2))
    52 timeaccess("ushorts", datasize>>1, 0xffff, extarray('H', datasize >> 1))
    53