Why so much difference in performance between Thread and Task?

后端 未结 6 1397
独厮守ぢ
独厮守ぢ 2020-12-14 16:36

Windows 7, Intel CORE i3, 64 bit, RAM 4Gb, 2.27 GHz
.NET Framework 4.0

I have the following code:

static void Main(string[] args)
{
             


        
6条回答
  •  有刺的猬
    2020-12-14 17:04

    You have an issue with your test, in that you don't wait for each Thread/Task to finish.

    Task uses a queue, so its much faster to create a Task than a Thread.

    I'll bet that even if you waited for Tasks/Threads to finish, that using a Task is faster. The overhead of creating and then destroying a Thread is high. That's why the Task.Factory was created!

提交回复
热议问题