Skip to content

Instantly share code, notes, and snippets.

@unionx

unionx/ask.py

Created Apr 28, 2014
Embed
What would you like to do?
对比一下CPython和PyPy的速度
#!/usr/bin/env python
import cProfile
def main():
for i in range(100000000):
i / 5.53892138021312312 * 23.23123121321321312
print(i)
cProfile.run("main()")
'''
% python --version
Python 2.7.5
% python ask.py
99999999
4 function calls in 12.158 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 12.158 12.158 <string>:1(<module>)
1 10.191 10.191 12.158 12.158 ask.py:4(main)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 1.967 1.967 1.967 1.967 {range}
% pypy --version
Python 2.7.3 (87aa9de10f9c, Nov 24 2013, 20:57:21)
[PyPy 2.2.1 with GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)]
% pypy ask.py
99999999
4 function calls in 0.122 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.122 0.122 <string>:1(<module>)
1 0.122 0.122 0.122 0.122 ask.py:4(main)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 0.000 0.000 0.000 0.000 {range}
'''
@KillDevil

This comment has been minimized.

Copy link

@KillDevil KillDevil commented Sep 1, 2014

来个fibs看看!

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