Created
January 26, 2015 18:30
-
-
Save ggreer/31cdc13150c7eb341750 to your computer and use it in GitHub Desktop.
Pypy is *fast*
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import random | |
matches = 0 | |
total = 1000000 | |
people = 5 | |
for i in range(total): | |
month = random.randrange(12) | |
for j in reversed(range(people - 1)): | |
if random.randrange(12) != month: | |
break | |
if j == 0: | |
print('Everyone has the same birth month: %s' % month) | |
matches += 1 | |
print('%s/%s %s%%' % (matches, total, (100 * matches/float(total)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggreer@boron:~% time python birth_month.py | |
... | |
python birth_month.py 7.99s user 0.04s system 98% cpu 8.186 total | |
ggreer@boron:~% | |
ggreer@boron:~% time python3 birth_month.py | |
... | |
python3 birth_month.py 11.91s user 0.02s system 99% cpu 11.943 total | |
ggreer@boron:~% | |
ggreer@boron:~% time ~/Downloads/pypy-2.4.0-linux64/bin/pypy birth_month.py | |
... | |
~/Downloads/pypy-2.4.0-linux64/bin/pypy birth_month.py 0.53s user 0.03s system 98% cpu 0.566 total | |
ggreer@boron:~% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment