第一种   System.DateTime

public static void SubTest()
{
DateTime beforeDT = System.DateTime.Now;
int[] a = new int[] { , , , , , , , , , , , , , , , , , , , , };
//Shuffle(a) is the function you want to test.
Shuffle(a);
DateTime afterDT = System.DateTime.Now;
TimeSpan ts = afterDT.Subtract(beforeDT);
Console.WriteLine("DateTime costed for Shuffle function is: {0}ms",ts.TotalMilliseconds);
}

第二种用Stopwatch类(System.Diagnostics)

 /// <summary>
/// 测试for循环优化
/// </summary>
/// <returns></returns>
[HttpGet("test")]
public ActionResult<ApiResponse> test()
{
var result = new ApiResponse();
Stopwatch sw = new Stopwatch();
sw.Start();
//耗时程序 sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine("DateTime costed for Shuffle function is: {0}ms", ts.TotalMilliseconds);
return result; }

转自:https://www.cnblogs.com/I-am-Betty/p/10489787.html

C# 计时程序运行时间的更多相关文章

  1. python 计时程序运行时间

    import time time_start=time.time() time_end=time.time() print('totally cost',time_end-time_start)

  2. VC中监测程序运行时间(二)-毫秒级

    /* * 微秒级计时器,用来统计程序运行时间 * http://blog.csdn.net/hoya5121/article/details/3778487#comments * //整理 [10/1 ...

  3. VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法

    1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...

  4. VC++程序运行时间测试函数

    0:介绍 我们在衡量一个函数运行时间,或者判断一个算法的时间效率,或者在程序中我们需要一个定时器,定时执行一个特定的操作,比如在多媒体中,比如在游戏中等,都会用到时间函数.还比如我们通过记录函数或者算 ...

  5. C++程序运行时间-ZZ

    [15.5.25]贴一段实用的代码,linux下跑过. #include <stdio.h> /* printf */ #include <time.h> /* clock_t ...

  6. VC程序运行时间测试函数

    VC程序运行时间测试函数 介绍 我们在衡量一个函数运行时间,或者判断一个算法的时间效率,或者在程序中我们需要一个定时器,定时执行一个特定的操作,比如在多媒体中,比如在游戏中等,都会用到时间函数.还比如 ...

  7. 【VS开发】VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法

    1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...

  8. 检测Java程序运行时间的2种方法(高精度的时间[纳秒]与低精度的时间[毫秒])

    第一种是以毫秒为单位计算的. 代码如下: long startTime=System.currentTimeMillis(); //获取开始时间 doSomeThing(); //测试的代码段 lon ...

  9. PAT乙级 1026. 程序运行时间(15)

    1026. 程序运行时间(15) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 要获得一个C语言程序的运行时间, ...

随机推荐

  1. .htaccess tricks总结

    目录 .htaccess tricks总结 一.什么是.htaccess 二.利用条件 三.利用方式 && tricks 1.将指定后缀名的文件当做php解析 2.php_value利 ...

  2. FileInputFormat 的实现之TextInputFormat

    说明 TextInputFormat默认是按行切分记录record,本篇在于理解,对于同一条记录record,如果被切分在不同的split时是怎么处理的.首先getSplits是在逻辑上划分,并没有物 ...

  3. ruby-on-rails-BUG

    Ruby on Rails errors: (新手期) rails 自动化部署教程 Q1: rvm 无法使用 $ rvm use 1.9.3 --default RVM is not a functi ...

  4. [Beta]Scrum Meeting#2

    github 本次会议项目由PM召开,时间为5月7日晚上10点30分 时长20分钟 任务表格 人员 昨日工作 下一步工作 木鬼 撰写博客整理文档 撰写博客 swoip 模块松耦合,文件结构调整为改进界 ...

  5. js中for..of..的使用和迭代器

    for..of是ES6中引入的新特性,它主要的作用是:循环一个可迭代的对象. 它可以循环遍历,数组.字符串.Set对象等等,先来看两个简单的例子: 遍历字符串 let str = 'Hello' fo ...

  6. Eclipse安装代码反编译插件Enhanced Class Decompiler

    在开发过程中,如果想查看引入资源的源代码,可以借助eclipse的插件Enhanced Class Decompiler轻松实现,下面我来讲解一下如何安装使用这个插件. 1.打开Eclipse菜单-& ...

  7. 累积分布函数(cumulative distribution function)

    sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程,QQ:231469242) https://study.163.com/course/introduction.htm?courseId ...

  8. dubbo连接过程

    场景1 启动时 dubbo服务提供端在Zookeeper上注册的节点目录:假设接口名称是:com.bob.dubbo.service.CityDubboService dubbo服务提供端连接到注册中 ...

  9. 基于webpack4的react开发环境配置

    一.基础配置 1.init项目 mkdir react-webpack4-cook cd react-webpack4-cook mkdir src mkdir dist npm init -y 复制 ...

  10. SQL存储实现将JSON自动转化成SQL数据列

    CREATE PROCEDURE sp_GetJsonFields ( @Json VARCHAR(MAX) ) AS BEGIN SELECT @Json=REPLACE(@Json,'{','') ...