~linaro-toolchain-dev/cortex-strings/trunk

1 by Michael Hope
Pulled in the initial versions
1
import ctypes
2
import timeit
3
import pprint
4
import gc
5
6
from pylab import *
7
8
plain = ctypes.cdll.LoadLibrary("install/lib/libplain.so")
9
helpers = ctypes.cdll.LoadLibrary("install/lib/libhelpers.so")
10
11
dest = ctypes.create_string_buffer(1024)
12
src = ctypes.create_string_buffer('Hi there', 1024)
13
14
def run(fun):
15
    timer = timeit.default_timer
16
    gcold = gc.isenabled()
17
    gc.disable()
18
19
    t0 = timer()
20
    fun()
21
    t1 = timer()
22
23
    if gcold:
24
        gc.enable()
25
26
    return t1 - t0
27
28
# Calculate a good number of loops
29
loops = 100000
30
31
while True:
32
    elapsed = run(lambda: helpers.spawniis(plain.memcpy, loops, dest, src, 20))
33
    print loops, elapsed
34
35
    if elapsed < 0.1:
36
        loops *= 10
37
    else:
38
        loops *= 2/elapsed
39
        base = 10**(int(math.log10(loops)))
40
        loops = int(loops/base + 1) * base
41
        print loops
42
        break
43
44
# Calculate the call overhead
45
elapsed = run(lambda: helpers.spawniis(helpers.bounce, loops, dest, src, 20))
46
47
print elapsed
48
49
elapsed = run(lambda: helpers.spawniis(plain.memcpy, loops, dest, src, 20))
50
print elapsed