1.
static void Main(string[] args)
{
Console.WriteLine("按回车开始遍历 2,000,000 条记录...");
Console.ReadLine();
int tickCount = Environment.TickCount;
int ret = 0;
for (int i = 0; i < 1000000; i++)
{
DataTime dt = new DataTime();
long ticks = dt.Ticks;
// 和调用DateTimeToTicks(。。)比较
}
tickCount = Environment.TickCount - tickCount;
Console.WriteLine("已完成遍历, 总共消耗时间: {0} 毫秒.", tickCount);
Console.ReadLine();
}
----------------------------------------------------
2.
static void Main(string[] args)
{
Console.WriteLine("按回车开始遍历 2,000,000 条记录...");
Console.ReadLine();
int tickCount = Environment.TickCount;
int ret = 0;
for (int i = 0; i < 1000000; i++)
{
DataTime dt1 =new DataTime(ticks);
// 和调用TicksToDateTime(...)比较
}
tickCount = Environment.TickCount - tickCount;
Console.WriteLine("已完成遍历, 总共消耗时间: {0} 毫秒.", tickCount);
Console.ReadLine();
}
-----------------------
long DateTimeToTicks(int year, int month, int day, int hour, int minute, int second)
{}
void TicksToDateTime(long ticks, ref int year, ref int month, ref int day, ref int hour, ref int minute, int second)
{}
然后自己模拟一下时间转换成毫秒 和毫秒转时间 测效率
循环几百万次测效率,并且要考虑 闰年