听说python在CPU核心多的时候速度反而慢

从这儿看到的
A GIL Adventure (with a happy ending)

写了个测试, 的确是, 环境是python2.6.5 x86, Win7, 双核

D:\works\stars\server\utils>pbench.py
4.767000 seconds for a 5 x 100000 multithread test
2.997000 seconds for a 5 x 100000 single thread test
multithread overhead: 59.059059%
set process affinity // 把进程绑到一个核心上
3.755000 seconds for a 5 x 100000 multithread test
2.909000 seconds for a 5 x 100000 single thread test
multithread overhead: 29.082166%

D:\works\stars\server\utils>pbench.py
4.699000 seconds for a 5 x 100000 multithread test
2.914000 seconds for a 5 x 100000 single thread test
multithread overhead: 61.256000%
set process affinity
3.910000 seconds for a 5 x 100000 multithread test
3.004000 seconds for a 5 x 100000 single thread test
multithread overhead: 30.159774%

Linux下更可观, 环境是python2.6.6 x64, CentOS, 双路x四核

[xxx@xxx test]# ./dist/pbench
6.152628 seconds for a 5 x 100000 multithread test
4.913056 seconds for a 5 x 100000 single thread test
multithread overhead: 25.230169%
set process affinity to 1
5.032502 seconds for a 5 x 100000 multithread test
4.931799 seconds for a 5 x 100000 single thread test
multithread overhead: 2.041912%

[xxx@xxx test]# ./dist/pbench
6.162305 seconds for a 5 x 100000 multithread test
4.903964 seconds for a 5 x 100000 single thread test
multithread overhead: 25.659672%
set process affinity to 6
5.070047 seconds for a 5 x 100000 multithread test
5.042279 seconds for a 5 x 100000 single thread test
multithread overhead: 0.550706%

Advertisements

No comments yet

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: