Debian Codegraph @

rpython/translator/goal/targetrpystonedalone.py

raw symbols SCIP
1 import os, sys
2 from rpython.translator.test import rpystone
3 from rpython.translator.goal import richards
4
5 # __________ Entry point __________
6
7 # note that we have %f but no length specifiers in RPython
8
9 def pystones_main(loops):
10 benchtime, stones = rpystone.pystones(abs(loops))
11 s = '' # annotator happiness
12 if loops >= 0:
13 s = ("RPystone time for %d passes = %f" %
14 (loops, benchtime) + '\n' + (
15 "This machine benchmarks at %f pystones/second\n" % stones))
16 os.write(1, s)
17 if loops == 12345:
18 pystones_main(loops-1)
19
20 def richards_main(iterations):
21 s = "Richards benchmark (RPython) starting...\n"
22 os.write(1, s)
23 result, startTime, endTime = richards.entry_point(iterations)
24 if not result:
25 os.write(2, "Incorrect results!\n")
26 return
27 os.write(1, "finished.\n")
28 total_s = endTime - startTime
29 avg = total_s * 1000 / iterations
30 os.write(1, "Total time for %d iterations: %f secs\n" %(iterations, total_s))
31 os.write(1, "Average time per iteration: %f ms\n" %(avg))
32
33 DEF_PYSTONE = 10000000
34 DEF_RICHARDS = 1000
35
36 def entry_point(argv):
37 proc = pystones_main
38 default = DEF_PYSTONE
39 n = 0
40 for s in argv[1:]:
41 s = s.lower()
42 if 'pystone'.startswith(s):
43 proc = pystones_main
44 default = DEF_PYSTONE
45 elif 'richards'.startswith(s):
46 proc = richards_main
47 default = DEF_RICHARDS
48 else:
49 try:
50 n = abs(int(s))
51 except ValueError:
52 os.write(2, '"%s" is neither a valid option (pystone, richards)'
53 ' nor an integer\n' % s)
54 return 1
55 if not n:
56 n = default
57 proc(n)
58 return 0
59
60 # _____ Define and setup target ___
61
62 def target(*args):
63 return entry_point
64
65 """
66 Why is this a stand-alone target?
67
68 The above target specifies no argument types list.
69 This is a case treated specially in the driver.py . The only argument is meant
70 to be a list of strings, actually implementing argv of the executable.
71 """