Why is my multi-threading slower than my single threading?

后端 未结 6 1698

I know a couple of people asked a question similar to this, but I can’t find any response that would make me understand why it\'s slower.

So, I made a little console

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-14 07:03

    Note that Process writes to the console (and basically does nothing else), and that output to the console (which here acts as a kind of shared resource) is slow and needs to be synchronized with the other threads.

    To my understanding, the parallelization you use creates a huge overhead but gains no speedup, because all of the time the threads are apparently mostly waiting for the other process to finish writing to the console.

提交回复
热议问题