~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
2 by Michael Hope
Made the different routines compile. Expanded the tests.
5
import math
1 by Michael Hope
Pulled in the initial versions
6
7
plain = ctypes.cdll.LoadLibrary("install/lib/libplain.so")
2 by Michael Hope
Made the different routines compile. Expanded the tests.
8
libc = ctypes.cdll.LoadLibrary("/lib/libc.so.6")
9
bionic = ctypes.cdll.LoadLibrary("install/lib/libbionic.so")
10
glibc = ctypes.cdll.LoadLibrary("install/lib/libglibc.so")
11
newlib = ctypes.cdll.LoadLibrary("install/lib/libnewlib.so")
1 by Michael Hope
Pulled in the initial versions
12
helpers = ctypes.cdll.LoadLibrary("install/lib/libhelpers.so")
13
2 by Michael Hope
Made the different routines compile. Expanded the tests.
14
dest = ctypes.create_string_buffer(1024*1024)
15
src = ctypes.create_string_buffer(('\x55' * 13) + '\0', 1024*1024)
16
17
overhead = 0
18
19
def round2(v):
20
    base = 10**(int(math.log10(v)))
21
    return int(v/base + 1) * base
1 by Michael Hope
Pulled in the initial versions
22
23
def run(fun):
24
    timer = timeit.default_timer
25
    gcold = gc.isenabled()
26
    gc.disable()
27
28
    t0 = timer()
29
    fun()
30
    t1 = timer()
31
32
    if gcold:
33
        gc.enable()
34
2 by Michael Hope
Made the different routines compile. Expanded the tests.
35
    elapsed = t1 - t0
36
37
    return elapsed
1 by Michael Hope
Pulled in the initial versions
38
39
# Calculate a good number of loops
40
loops = 100000
41
42
while True:
43
    elapsed = run(lambda: helpers.spawniis(plain.memcpy, loops, dest, src, 20))
44
45
    if elapsed < 0.1:
46
        loops *= 10
47
    else:
2 by Michael Hope
Made the different routines compile. Expanded the tests.
48
        loops = round2(loops*2/elapsed)
1 by Michael Hope
Pulled in the initial versions
49
        print loops
50
        break
51
2 by Michael Hope
Made the different routines compile. Expanded the tests.
52
limit = 512*1024
53
step = 2
54
last = None
55
56
#small = range(4096, limit, 4096)
57
big = [int(step**x) for x in range(1, int(math.log(limit)/math.log(step)+1))]
58
big = []
59
small = range(1, 3)
60
steps = sorted(list(set(big) | set(small)))
61
62
print steps
63
64
for size in steps:
65
    if size >= 8:
66
        l = round2(int(loops*30/size))
67
    else:
68
        l = loops
69
70
    # tests = [
71
    #     lambda: helpers.spawniis(helpers.bounce, l, dest, src, size),
72
    #     lambda: helpers.spawniis(plain.memcpy, l, dest, src, size),
73
    #     lambda: helpers.spawniis(plain.memcpy2, l, dest, src, size),
74
    #     lambda: helpers.spawniis(libc.memcpy, l, dest, src, size),
75
    #     lambda: helpers.spawniis(glibc.memcpy, l, dest, src, size),
76
    #     lambda: helpers.spawniis(bionic.memcpy, l, dest, src, size),
77
    #     ]
78
    # tests = [
79
    #     lambda: helpers.spawniis(helpers.bounce, l, dest, src, size),
80
    #     lambda: helpers.spawniis(libc.strcpy, l, dest, src, size),
81
    #     lambda: helpers.spawniis(newlib.strcpy, l, dest, src, size)
82
    #     ]
83
    tests = [
84
        lambda: helpers.spawniis(helpers.bounce, l, dest, src, size),
85
        lambda: helpers.spawniis(libc.strlen, l, src, src, size),
86
        lambda: helpers.spawniis(glibc.strlen, l, src, src, size),
87
        lambda: helpers.spawniis(bionic.strlen, l, src, src, size),
88
        lambda: helpers.spawniis(newlib.strlen, l, src, src, size),
89
        ]
90
91
    results = [size, l] + [run(x) for x in tests]
92
    print '\t'.join('%s' % x for x in results)