问题描述
几年前,在Windows环境下,我做了一些测试,通过让CPU的计算密集型+内存访问密集型+ I / O访问密集型应用程序运行多个实例。我开发了两个版本:一个是多任务处理下运行,另一种是在多线程运行
。我发现性能多的多处理好。我读别的地方(但我不记得站点)。
其中规定,原因是在多线程,它们是激战的单条内存流水线和I / O管道,相对于多处理器使得性能更差
不过,我找不到那篇文章了。我想知道,直到今天,下面是否仍然适用?
It depends on how much the various threads or processes (I'll be using the collective term "tasks" for both of them) need to communicate, especially by sharing memory: that's easy, cheap and fast for threads, but not at all for processes, so, if a lot of it is going on, I bet processes' performance is not going to beat threads'.
Also, processes (esp. on Windows) are "heavier" to get started, so if a lot of "task starts" occur, again threads can easily beat processes in terms of performance.
Next, you can have CPUs with "hyperthreading", which can run (at least) two threads on a core very rapidly -- but, not processes (since the "hyperthreaded" threads cannot be using distinct address spaces) -- yet another case in which threads can win performance-wise.
If none of these considerations apply, then the race should be no better than a tie, anyway.
这篇关于对于多线程和多进程的性能差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!