<pre name="code" class="csharp"><span style="font-size:18px;">using System;
using System.Collections.Generic;
class Sentence
{
static void Main()
{
double ticks0 = DateTime.Now.Ticks;
for (int i = 0; i < int.MaxValue; i++)
{
// ...
}
double ticks1 = DateTime.Now.Ticks;
double n = (ticks1 - ticks0) / 10000000;
Console.WriteLine("上面这段程序运行了{0}秒", n);
Console.ReadLine();
}
} </span>
DateTime.Now.Ticks;每个计时周期表示一百纳秒,即一千万分之一秒。 1 毫秒内有 10,000 个计时周期。
此属性的值表示自 0001 年 1 月 1 日午夜 12:00:00以来经过的以 100 纳秒为间隔的间隔数。 它不包括归因于闰秒的嘀嗒数。