第一种   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. 如何优雅地执行dubbo"单测"

    很多小伙伴所在的公司是基于Dubbo来构建技术栈的,日常开发中必不可少要写dubbo单测(单元测试),如果单测数据依赖已有的外部dubbo服务,一般是mock数据,如果数据比较复杂,其实mock数据也 ...

  2. 冰多多团队-第八次Scrum例会

    冰多多团队-第八次Scrum会议 工作情况 团队成员 已完成任务 待完成任务 zpj debug, IAT debug, IAT 牛雅哲 将语音部分迁移到IatDemo上,去将科大讯飞的语音听写dem ...

  3. 最长公共子序列长度(dp)

    /// 求两个字符串的最大公共子序列长度,最长公共子序列则并不要求连续,但要求前后顺序(dp) #include <bits/stdc++.h> using namespace std; ...

  4. Windows系统中CreateFileMapping实现的共享内存及用法

    在32位的Windows系统中,每一个进程都有权访问他自己的4GB(232=4294967296)平面地址空间,没有段,没有选择符,没有near和far指针,没有near和far函数调用,也没有内存模 ...

  5. The Rise of Meta Learning

    The Rise of Meta Learning 2019-10-18 06:48:37 This blog is from: https://towardsdatascience.com/the- ...

  6. List和数组的互转

    list转数组: /要转换的list集合 List<String> testList = new ArrayList<String>(){{add("aa" ...

  7. 【C++】C++中explicity关键字的使用

    读者可以尝试预言一下这段代码的输出: #include <iostream> using namespace std; class Complex { private: double re ...

  8. git rebase使用场景

    1. 当前分支落后拉取后,整理commit,使得提交历史为直线 git pull = git fetch + git merge git pull --rebase = git fetch + git ...

  9. Hive学习笔记——metadata

    Hive结构体系 https://blog.csdn.net/zhoudaxia/article/details/8855937 可以在hive的jdbc接口中使用getMetaData方法来获取hi ...

  10. Jmeter+nfluxDB+Grafana性能监控平台

    下载地址: nfluxDB下载地址:https://portal.influxdata.com/downloads/ Grafana下载地址:https://grafana.com/grafana/d ...