我在一个小函数上使用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
有关为什么命令行python速度慢得多的想法?提前致谢.