2
我運行下面的程序慢17%:多線程cstringio是在Ubuntu 14.04
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'](https://docs.python.org/2/library/timeit.html)模塊再次分析程序。就像比較一樣。 –