C#检查一段代码的消耗时间

0.0 如果你想检查某一个函数循环的时间

System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();

        stopwatch.Start();



        //这里是你想检测的时间



        stopwatch.Stop();

        System.TimeSpan timeSpan = stopwatch.Elapsed;

        double hours = timeSpan.TotalHours;

        double minutes = timeSpan.TotalMinutes;

        double seconds = timeSpan.TotalSeconds;

        double milliseconds = timeSpan.TotalMilliseconds;





        Debug.Log("总小时:" + hours);

        Debug.Log("总分钟:" + minutes);

        Debug.Log("总秒:" + seconds);

        Debug.Log("总毫秒:" + milliseconds);

你可能感兴趣的:(C#)