【发布时间】:2015-12-02 17:57:12
【问题描述】:
我正在运行以下程序:
import cStringIO
import time
import threading
def func(tid):
buff = 'a'*4096
i = 0
while (i < 40000000):
output = cStringIO.StringIO()
output.write(buff)
contents = output.getvalue()
output.close()
i = i + 1
threads = 16
threadlist = []
start = time.time()
for tc in range(threads):
thr = threading.Thread(target=func, args=(tc,))
threadlist.append(thr)
thr.start()
for thr in threadlist:
thr.join()
end = time.time()
print "Time taken is %s" % (end - start)
在具有完全相同硬件但一台运行 ubuntu 10.04 而另一台运行 14.04 的机器上。我观察到 10.04 需要 1409.54 秒,而 14.04 需要 1656.81 秒,显示 14.04 性能下降 17%。有什么想法吗?
【问题讨论】:
-
你试过转换成python3吗?同时对 python3 进行了重大的性能改进。还有一点,你检查过每个系统上的python版本了吗?
-
@BeowulfOF python3 不是一个选择,主要是因为它目前提供的软件包支持有限。我在两台机器上都安装并使用了相同的 python 版本,即 2.7.8。
-
我建议使用
timeit模块再次分析程序。只是作为一个比较。
标签: python multithreading ubuntu cstringio