2

我正在运行以下程序:

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%。有任何想法吗?

4

1 回答 1

0

此行为是由于 14.04 上的超线程。有趣的是,在我的 2 核机器上禁用超线程(并在单个超线程上有效运行)后,14.04 的性能与 10.04 相当。

于 2015-09-29T05:25:45.257 回答