Source

hack2 / bench / numeric / arr.py

Full commit

import sys, struct

try:
    from numpypy import zeros, fromstring
    from _numpypy.pypy import remove_invalidates
except:
    from numpy import zeros
    remove_invalidates = lambda arg: None

def hook(jitdriver_name, loop_type, greenkey, operations):
    return [i for i in operations if 'assert' not in str(i)]

try:
    import pypyjit
#    pypyjit.set_optimize_hook(hook)
except:
    pass

size = int(sys.argv[1])

def init():
    with open("/tmp/a.data") as f:
        return fromstring(f.read(), dtype=float)

count = int(sys.argv[2])
a, b, c, d, e = [init() for i in range(5)]
scenario = int(sys.argv[3])
r = zeros(size)
for i in range(count):
    if scenario == 0:
        r[:] = a + b
    elif scenario == 1:
        r[:] = a + (b + c)
    elif scenario == 2:
        r[:] = (a + b) + ((c + d) + e)
print r.sum()