Today wrote the Loop section code, but feel like the performance is very poor appearance, want to look at the entire cycle of execution time, at first I think of DateTime.Now, but the strange thing is, if I cycle less than 30,000 times (less than a few words) will find 2 time interval is the same! Whether it is DateTime.Now.Tick or DateTime.Now.TimeOfDay.ToString (), the Internet to find information, it seems that datetime.now accuracy is relatively low, looking for a long time finally find a solution, direct sticker Code
Private Static voidTest () { Do{Console.Write ("Number:"); intnum =Convert.ToInt32 (Console.ReadLine ()); Stopwatch SW=NewStopwatch (); Sw. Start (); for(inti =0; i < num; i++) { intA =1; } SW. Stop (); Console.WriteLine ("spents:"+SW. Elapsedticks); Console.WriteLine ("*******************************"); } while(1==1); }
C # Records cycle consumption time