Using PyPy to run a Python program?

Jonny picture Jonny · Sep 20, 2014 · Viewed 18k times · Source

I have been told that you can use PyPy to run Python programs, which is a lot faster as it is compiled using a JIT compiler rather than interpreted.

The following program finds the largest prime factor of the number 600851475143:

import numpy as np

nr = 600851475143
n = 2

while n <= np.sqrt(nr):
    if nr%n == 0:
        nr = nr/n
    n += 1
print(nr)

What would be the procedure to run this using PyPy?

I know there is documentation on their site, but I do not understand it and would appreciate a demonstration.

Answer

simonzack picture simonzack · Sep 20, 2014

Add this shebang line to the top of the program:

#!/usr/bin/env pypy

If you want to do this manually, just enter pypy main.py on the command-line.