小编Ken*_*n L的帖子

python交互式shell比命令行快16倍 - 出了什么问题?

我在一个小函数上使用Enthought EPD-Free 7.3-1,当我剪切/粘贴到交互式会话(PyLab)并运行它时,它只需不到一秒钟.当我从命令行" python probtest.py" 运行相同的代码时,它需要超过16秒.

我已经确认两者都在使用相同的python环境.也许相关(也许不是)但是在.py文件目录中,没有.pyc文件......我最近做过的python脚本都没有关联的.pyc文件.我检查了文件夹的读/写权限,使用了"修复权限"(Mac OSX-Lion),并卸载/重新安装了EPD_Free python,但没有运气.

我不知道可能是什么原因.我正在使用的代码(x个骰子的简单测试,寻找至少y六个):

import numpy as np
import sys

def runTest(numDice, numSixes, numThrows = 10000):
    nSuccess = 0
    for i in range(numThrows):
        dList = np.random.randint(1,7,numDice)
        if sum(dList==6) >= numSixes:
            nSuccess += 1
    return float(nSuccess)/numThrows

print runTest(900,150,5000)
print sys.version 
Run Code Online (Sandbox Code Playgroud)

有关为什么命令行python速度慢得多的想法?提前致谢.

python command-line interactive

7
推荐指数
1
解决办法
397
查看次数

标签 统计

command-line ×1

interactive ×1

python ×1