Task task = Task.Delay(TimeSpan.FromSeconds(1)); tasks.Add(task);
The difference is quite significant.
(1) With the authors code (using Task.Run), I get ~428MB of allocations.
(2) Dropping the unnecessary Task.Run(...), I get ~183MB of allocations.
(3) Doing (2) and waiting N times on the same delay, I get ~39MB of allocations.
This was all using .NET 6 too. .NET 7 or the 8 preview might be even better since they are working hard on performance in recent releases.
So even looking at just (2), that puts .NET on par with the rust library.
The difference is quite significant.
(1) With the authors code (using Task.Run), I get ~428MB of allocations.
(2) Dropping the unnecessary Task.Run(...), I get ~183MB of allocations.
(3) Doing (2) and waiting N times on the same delay, I get ~39MB of allocations.
This was all using .NET 6 too. .NET 7 or the 8 preview might be even better since they are working hard on performance in recent releases.
So even looking at just (2), that puts .NET on par with the rust library.