在一些需要隔時觸發的場景中,如javascript中的setInterval函數,在.Net中,你用什麼?
是System.Timer.Timer?
or
while(true)
{
Thread.Sleep(1000);
}
今天比較一下Timer和Sleep.
結果:
Thread.sleep,問天下誰於爭峰。
空間:
Type |
work set |
virtual bytes |
page file bytes |
Thread Count |
Handle |
Timer
8.990.720
114.978.816
11.444.224
4
115
Thread.Sleep
6.590464
104.296.448
7.143.424
3
95
Thread.Sleep全勝
時間:
Type |
start Time |
Interval |
times |
finish time |
Timer
11:53:37:416
10ms
100000
12:19:37:555
Thread.Sleep
11:53:37:432
10ms
100000
12:19:36:713