码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-05-11 18:05:52      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

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; }
}

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

标签:

原文地址:http://www.cnblogs.com/plateFace/p/5482682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!