Created
July 9, 2015 16:10
-
-
Save thomas-mangin/52a938e5b2672da877f5 to your computer and use it in GitHub Desktop.
python vs pypy
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
def benchmark (label, func, count, *args, **kwargs): | |
s = time.time() | |
d = None | |
for _ in range(count): | |
d = func(*args, **kwargs) | |
e = time.time() | |
print('%s: %7d requests in %1.03f seconds' % (label, count, e-s)) | |
print('%6.03f requests/second' % (count/(e-s))) | |
print() | |
return d | |
def func (): | |
pass | |
if __name__ == '__main__': | |
benchmark('empty function', func, 100000000) | |
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
☿ env PYTHONPATH=lib/ python xxx.py | |
empty function: 100000000 requests in 17.460 seconds | |
5727218.404 requests/second | |
() | |
☿ env PYTHONPATH=lib/ pypy xxx.py | |
empty function: 100000000 requests in 0.147 seconds | |
681873145.672 requests/second | |
() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
☿ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
☿ pypy
Python 2.7.9 (295ee98b69288471b0fcf2e0ede82ce5209eb90b, Jun 02 2015, 18:26:45)
[PyPy 2.6.0 with GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.