2008/4/3 俊杰蔡 <yzcai...@gmail.com>:
--
Any complex technology which doesn't come with documentation must be the best
available.
python也是打开关闭一次。 用 xrange 可以提高一点点。剩下的实在没办法了,io函数的性能问题吧
hi,all:
同事闲聊,比较下perl和python的效率。 以下是计算5000000个7位随机数模3 ,并打入文件,一行一个。结果测试发现,python比perl慢了12倍,各位有好办法优化优化么?
perl:
#!/usr/bin/perl -w
use strict;
open (WW,"> 500000") or die "$!";
foreach(1..5000000){
my $i = int(rand 10000000) % 3;
print WW $i."\n";
}
close WW;
python:
import random
import time
__revision__ = '0.1'
def test():
fh = open("test_cjj","w",500000)
for i in range(5000000):
data = random.randrange(1000000,9999999,1)
yu = data % 3
fh.write(str(yu)+"\n")
fh.close()
if __name__ == "__main__" :
test()
运行结果:
time ./500.pl
real 0m2.119s
user 0m2.111s
sys 0m0.008s
time ./a.py
real 6m35.764s
user 4m42.762s
sys 1m47.011s
--
'''过程改进乃是开始催生可促生靠谱的人的组织!
PI keeps evolving organizations which promoting people be good!
'''http://zoomquiet.org
Pls. usage OOo to replace M$ Office. http://zh.openoffice.org
Pls. usage 7-zip to replace WinRAR/WinZip. http://7-zip.org
You can get the truely Freedom 4 software.
详细记要在:
http://wiki.woodpecker.org.cn/moin/MicroProj/2008-04-03
的确 很蟒,很暴力!
--
'''过程改进乃是开始催生可促生靠谱的人的组织!
PI keeps evolving organizations which promoting people be good!
'''http://zoomquiet.org
Pls. usage OOo to replace M$ Office. http://zh.openoffice.org
Pls. usage 7-zip to replace WinRAR/WinZip. http://7-zip.org
最后还是最真觉的方式最快: Simple is better ;)
不过,在不使用C加速前,的确是使用生成器的迭代计算要快
2008/4/4 jerryji <jerry...@gmail.com>:
Pls. usage OOo to replace M$ Office. http://zh.openoffice.org
Pls. usage 7-zip to replace WinRAR/WinZip. http://7-zip.org
在 08-4-4,boost...@yahoo.com.cn<boost...@googlemail.com> 写道:
期望没有人使用汇編再来整了.. ;)
2008/4/5 俊杰蔡 <yzcai...@gmail.com>:
--
'''过程改进乃是开始催生可促生靠谱的人的组织!
PI keeps evolving organizations which promoting people be good!
'''http://zoomquiet.org
Pls. usage OOo to replace M$ Office. http://zh.openoffice.org
Pls. usage 7-zip to replace WinRAR/WinZip. http://7-zip.org