lhmouse / mcfgthread

Cornerstone of the MOST efficient std::thread on Windows for mingw-w64
https://gcc-mcf.lhmouse.com/
Other
269 stars 28 forks source link

Update benchmark results #54

Closed CarterLi closed 2 years ago

CarterLi commented 2 years ago

RT

lhmouse commented 2 years ago

The old benchmark was done on a Windows 7 machine. It looks like that the SRWLOCK has improved a lot in Windows 10. I would like to optimize it a little before that.

lhmouse commented 2 years ago

Done now: https://github.com/lhmouse/mcfgthread/blob/master/README.md#benchmarking

CarterLi commented 2 years ago

Done now: https://github.com/lhmouse/mcfgthread/blob/master/README.md#benchmarking

Does it mean that MCF is even slower than PTHR? What happened when #THRD > 60?

I saw that MCF lock uses spinlock to reduce syscalls. For current benchmark program there is very high possiblity that the program never enters the NtWaitForKeyedEvent syscall.

What if there are more things to do when locking so that the program can hit the NtWaitForKeyedEvent syscall?

lhmouse commented 2 years ago

Does it mean that MCF is even slower than PTHR? What happened when #THRD > 60?

I suspect the hash table has been used up. This is practically not a problem, as seldom do people create 60 threads that are all jammed on a single mutex.

I saw that MCF lock uses spinlock to reduce syscalls. For current benchmark program there is very high possiblity that the program never enters the NtWaitForKeyedEvent syscall.

What if there are more things to do when locking so that the program can hit the NtWaitForKeyedEvent syscall?

No, you should run the test yourself; the number of spinning threads is not unlimited. It is possible to make threads spin infinitely by replacing while(--spin >= 0) with for(;;), however I am sure it will only make your test program run slower, due to increment of bus pressure.

CarterLi commented 2 years ago

蛋疼,俩中国人还要用英文交流。。。

No, you should run the test yourself; the number of spinning threads is not unlimited. It is possible to make threads spin infinitely by replacing while(--spin >= 0) with for(;;), however I am sure it will only make your test program run slower, due to increment of bus pressure.

我的意思是现在的benchmark基本上是在测你写的spinlock的速度,跟 NtWaitForKeyedEvent 没啥关系。我想知道 NtWaitForKeyedEvent 和 AcquireSRWLockExclusive 的速度比较

spinlock 总有 hold 不住的情况

lhmouse commented 2 years ago

是啊你为什么不自己试一试呢,无脑 spin 跑一分钟都跑不出来结果,就不是几秒钟的事了。无脑 wait 大概会慢一倍。