| 1 |
import os |
| 2 |
|
| 3 |
|
| 4 |
modfilename = os.path.join(os.path.dirname(__file__), 'richards.py') |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
DEFAULT_CODE_SIZE_FACTOR = 10 |
| 13 |
take_options = True |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
def richards_main(fn, iterations): |
| 19 |
s = "Richards benchmark (RPython) starting...\n" |
| 20 |
os.write(1, s) |
| 21 |
result, startTime, endTime = fn(iterations) |
| 22 |
if not result: |
| 23 |
os.write(2, "Incorrect results!\n") |
| 24 |
return False |
| 25 |
os.write(1, "finished.\n") |
| 26 |
total_s = endTime - startTime |
| 27 |
avg = total_s * 1000 / iterations |
| 28 |
os.write(1, "Total time for %d iterations: %f secs\n" %(iterations, total_s)) |
| 29 |
os.write(1, "Average time per iteration: %f ms\n" %(avg)) |
| 30 |
return True |
| 31 |
|
| 32 |
|
| 33 |
def entry_point(argv): |
| 34 |
for fn in functions: |
| 35 |
if not richards_main(fn, 10): |
| 36 |
return 1 |
| 37 |
return 0 |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
def target(driver, args, config): |
| 42 |
global modules, functions |
| 43 |
if len(args) == 0: |
| 44 |
N = DEFAULT_CODE_SIZE_FACTOR |
| 45 |
elif len(args) == 1: |
| 46 |
N = int(args[0]) |
| 47 |
else: |
| 48 |
raise ValueError("too many command-line arguments") |
| 49 |
|
| 50 |
modules = [] |
| 51 |
functions = [] |
| 52 |
f = open(modfilename) |
| 53 |
source = f.read() |
| 54 |
f.close() |
| 55 |
for i in range(N): |
| 56 |
d = {'__name__': 'richards%d' % i} |
| 57 |
exec(source, d) |
| 58 |
modules.append(d) |
| 59 |
functions.append(d['entry_point']) |
| 60 |
|
| 61 |
return entry_point, None |