Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于加速比 #7

Open
SpencerChou opened this issue Feb 14, 2023 · 7 comments
Open

关于加速比 #7

SpencerChou opened this issue Feb 14, 2023 · 7 comments

Comments

@SpencerChou
Copy link

您好,我看到你的benchmark中提到了加速比,我主要是没感觉到这个指标的意义是在哪呢?
单线程4个task,200s
然后线程池4个task50s,这是很正常的。。

但是当任务达到8、16的时候,总耗时为啥会减少呢?我没有想到原因,能否解释一下啊

@CodingHanYa
Copy link
Owner

计算的是单个任务的耗时而不是总耗时哦。

@SpencerChou
Copy link
Author

我的疑问正来于此,任务并没有并行化,所以对于每个线程任务耗时为啥会减少那么多呢? 考虑到任务窃取等也没有道理啊,有的线程执行时间短了,就有的更长,平均下来应该也是200/4=50上下不是嘛

@CodingHanYa
Copy link
Owner

假设单条线程执行速度不变,但是线程数增多了。那么单位时间内处理的任务增多了,每个任务的平均耗时就降下来了。你把每个任务当成大任务分解出来的小任务,那么实际上就是任务并行化了。

@SpencerChou
Copy link
Author

我又去看了下代码,然后在看了看benchmark的数据,感觉更懵了
single thread的测试,测出来的是平均下来,那个cpu_bound的函数执行要200多ms,
多线程,那个cpu_bound的函数执行却只要20ms。。。
vecnums和vecsize又没变,问题计算规模又没变小,只是更多个相同的任务在不同的线程上多次计算了,平均耗时怎么会降低呢?

@CodingHanYa
Copy link
Owner

你再想想

@SpencerChou
Copy link
Author

大概知道了,还有就是 ,跑空任务的这个意义是在哪呢,这个benchmark能体现线程池的什么能力

@CodingHanYa
Copy link
Owner

你可以看看我在B站上的讲解视频。跑空任务越快,主要说明主线程同步任务到异步线程的开销越小。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants