File: targetrpystonedalone.py

package info (click to toggle)
pypy 5.6.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 97,040 kB
  • ctags: 185,069
  • sloc: python: 1,147,862; ansic: 49,642; cpp: 5,245; asm: 5,169; makefile: 529; sh: 481; xml: 232; lisp: 45
file content (71 lines) | stat: -rw-r--r-- 2,093 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os, sys
from rpython.translator.test import rpystone
from rpython.translator.goal import richards

# __________  Entry point  __________

# note that we have %f but no length specifiers in RPython

def pystones_main(loops):
    benchtime, stones = rpystone.pystones(abs(loops))
    s = '' # annotator happiness
    if loops >= 0:
        s = ("RPystone time for %d passes = %f" %
             (loops, benchtime) + '\n' + (
             "This machine benchmarks at %f pystones/second\n" % stones))
    os.write(1, s)
    if loops == 12345:
        pystones_main(loops-1)

def richards_main(iterations):
    s = "Richards benchmark (RPython) starting...\n"
    os.write(1, s)
    result, startTime, endTime = richards.entry_point(iterations)
    if not result:
        os.write(2, "Incorrect results!\n")
        return
    os.write(1, "finished.\n")
    total_s = endTime - startTime
    avg = total_s * 1000 / iterations
    os.write(1, "Total time for %d iterations: %f secs\n" %(iterations, total_s))
    os.write(1, "Average time per iteration: %f ms\n" %(avg))

DEF_PYSTONE = 10000000
DEF_RICHARDS = 1000

def entry_point(argv):
    proc = pystones_main
    default = DEF_PYSTONE
    n = 0
    for s in argv[1:]:
        s = s.lower()
        if 'pystone'.startswith(s):
            proc = pystones_main
            default = DEF_PYSTONE
        elif 'richards'.startswith(s):
            proc = richards_main
            default = DEF_RICHARDS
        else:
            try:
                n = abs(int(s))
            except ValueError:
                os.write(2, '"%s" is neither a valid option (pystone, richards)'
                            ' nor an integer\n' % s)
                return 1
    if not n:
        n = default
    proc(n)
    return 0

# _____ Define and setup target ___

def target(*args):
    return entry_point

"""
Why is this a stand-alone target?

The above target specifies no argument types list.
This is a case treated specially in the driver.py . The only argument is meant
to be a list of strings, actually implementing argv of the executable.
"""