Reputation: 1686
Is there a difference (from performance perspective) between:
Thread.Sleep(10000);
and
for(int i=0; i<100; i++)
{
Thread.Sleep(100);
}
Does the single call to Thread.Sleep(10000)
also results in context switches within this 10 seconds (so the OS can see if it's done sleeping), or is this thread really not served for 10 seconds?
Upvotes: 2
Views: 1030
Reputation: 1356
in any case second loop will take time because of following overheads
Upvotes: 1
Reputation: 16983
The second code (for loop) requires more process swaps and should be little slower than Thread.Sleep(10000);
Anyway you can use System.Diagnostics.Stopwatch
class to determine the exact time for these two approaches. I believe the difference will be very very small.
Upvotes: 2