空间:
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 |
Timer和Thread.Sleep打个平手,但Thread.sleep还是要强那么一点
分析:
Thread.sleep直接调用内核的指令,所在线程挂起,CPU执行队列的重排序。
Timer每次Elapsed会在线程池中取新的线程来执行,存在多次访问线程池的损耗。