简单的查看函数时间运行类

using UnityEngine;
using System.Collections;
using System.Diagnostics;
using System;

public class PerformanceTest
{
    public static PerformanceData Execute(Action action, int runCount)
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();
        for (int i = 0; i < runCount; i++)
        {
            action();
        }
        sw.Stop();

        double a = sw.ElapsedMilliseconds / (double)runCount;

        return new PerformanceData()
        {
            TotalMilliseconds = sw.ElapsedMilliseconds,
            MeanMilliseconds = sw.ElapsedMilliseconds / runCount
        };
    }
}

public class PerformanceData
{
    public double TotalMilliseconds { get; set; }
    public double MeanMilliseconds { get; set; }
}
posted @ 2016-05-11 17:18  盘子脸  阅读(396)  评论(0编辑  收藏  举报