Stopwatchクラスを利用して、処理時間を正確に計測できます。 using System; using System.Diagnostics; class StopWatchSample { static void Main() { Stopwatch sw = new Stopwatch(); sw.Start(); System.Threading.Thread.Sleep(1000); sw.Stop(); // ミリ秒単位で出力 long millisec = sw.ElapsedMilliseconds; Console.WriteLine(millisec); // 出力例:998 // TimeSpan構造体で書式付き表示 TimeSpan ts = sw.Elapsed; Console.WriteLine(ts); // 出力例:00:00:00.9984668 //一般的にこれを利用する。 // 高分解能なタイマが利用可能か Console.WriteLine(Stopwatch.IsHighResolution); // 出力例:True // タイマ刻み回数 long ticks = sw.ElapsedTicks; Console.WriteLine(ticks); // 出力例:2988141812 // タイマの1秒あたりの刻み回数 Console.WriteLine(Stopwatch.Frequency); // 出力例:2992730000 // より詳細な秒数 double sec = (double)sw.ElapsedTicks / (double)Stopwatch.Frequency; Console.WriteLine(sec); // 出力例:0.998466888760429 } } 中古車買取実績No.1ガリバー コメント: |