Example #1
0
    def test_setup(self):
        # this just checks that the module is setting up things correctly, and
        # the resulting code makes sense on top of CPython.
        import pypyjit

        def f(x, y):
            return x * y + 1

        assert f(6, 7) == 43
        pypyjit.enable(f.func_code)
        assert f(6, 7) == 43

        def gen(x):
            i = 0
            while i < x:
                yield i * i
                i += 1

        assert list(gen(3)) == [0, 1, 4]
        pypyjit.enable(gen.func_code)
        assert list(gen(3)) == [0, 1, 4]
Example #2
0
    def test_setup(self):
        # this just checks that the module is setting up things correctly, and
        # the resulting code makes sense on top of CPython.
        import pypyjit

        def f(x, y):
            return x*y+1

        assert f(6, 7) == 43
        pypyjit.enable(f.func_code)
        assert f(6, 7) == 43

        def gen(x):
            i = 0
            while i < x:
                yield i*i
                i += 1

        assert list(gen(3)) == [0, 1, 4]
        pypyjit.enable(gen.func_code)
        assert list(gen(3)) == [0, 1, 4]
Example #3
0
    print "finished."
    total_s = endTime - startTime
    print "Total time for %d iterations: %.2f secs" %(iterations,total_s)
    print "Average time per iteration: %.2f ms" %(total_s*1000/iterations)
    return 42

try:
    import sys
    if '-nojit' in sys.argv:
        sys.argv.remove('-nojit')
        raise ImportError
    import pypyjit
except ImportError:
    pass
else:
    import types
    for item in globals().values():
        if isinstance(item, types.FunctionType):
            pypyjit.enable(item.func_code)
        elif isinstance(item, type):
            for it in item.__dict__.values():
                if isinstance(it, types.FunctionType):
                    pypyjit.enable(it.func_code)
    
if __name__ == '__main__':
    import sys
    if len(sys.argv) >= 2:
        main(iterations = int(sys.argv[1]))
    else:
        main()
Example #4
0
import time


def f(n):
    if n > 1:
        return n * f(n - 1)
    else:
        return 1


import pypyjit
pypyjit.enable(f.func_code)

print f(7)
    print("Total time for %d iterations: %.2f secs" % (iterations, total_s))
    print("Average time per iteration: %.2f ms" %
          (total_s * 1000 / iterations))
    return 42


try:
    import sys
    if '-nojit' in sys.argv:
        sys.argv.remove('-nojit')
        raise ImportError
    import pypyjit
except ImportError:
    pass
else:
    import types
    for item in globals().values():
        if isinstance(item, types.FunctionType):
            pypyjit.enable(item.func_code)
        elif isinstance(item, type):
            for it in item.__dict__.values():
                if isinstance(it, types.FunctionType):
                    pypyjit.enable(it.func_code)

if __name__ == '__main__':
    import sys
    if len(sys.argv) >= 2:
        main(iterations=int(sys.argv[1]))
    else:
        main()
Example #6
0
import time


def f(n):
    if n > 1:
        return n * f(n - 1)
    else:
        return 1


import pypyjit

pypyjit.enable(f.func_code)

print f(7)