Skip to content

Instantly share code, notes, and snippets.

@thomas-mangin
Created July 9, 2015 16:10
Show Gist options
  • Save thomas-mangin/52a938e5b2672da877f5 to your computer and use it in GitHub Desktop.
Save thomas-mangin/52a938e5b2672da877f5 to your computer and use it in GitHub Desktop.
python vs pypy
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)
☿ 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
()
@thomas-mangin
Copy link
Author

☿ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment