pypy解释器简单测试

运行环境,windows 7

C:\pypy>pypy.exe --version
Python 3.2.3 (d63636b30cc0, Jul 30 2013, 07:02:44)
[PyPy 2.1.0-beta1 with MSC v.1500 32 bit]

C:\pypy>python --version
Python 2.7.3

 运行下面的代码

import time
from time import clock
 
def check(num):
    a = list(str(num))
    b = a[::-1]
    if a == b:
        return True
    return False
 
 
def main():
    all = range(1,10**7)
    for i in all:
        if check(i):
            if check(i**2):
                print(i,i**2)
 
 
if __name__ == '__main__':
    start = clock()
    main()
    end = clock()
    print (end-start)

 cpython耗时11.7s,pypy耗时6.4s

 脚本中可以指定解释器

cpython

#!/usr/bin/env: python


pypy

#!/usr/bin/env: pypy

参考——http://www.simonzhang.net/?p=1854

你可能感兴趣的:(测试)