第一种   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. 第08组 Beta冲刺(3/4)

    队名 八组评分了吗 组长博客链接(2分) 组员1李昕晖(组长) 过去两天完成了哪些任务 文字/口头描述 了解各个小组的进度与难以攻破的地方,晚上安排开会,安排新的冲刺任务. 重新分配小组及个人任务. ...

  2. Guava集合工具

    JDK提供了一系列集合类,如下所示,极大的方便了开发工作,并针对这些类提供了一个工具类java.util.Collections,Guava在此基础上添加了一些常用工具类方法,相比于java.util ...

  3. python skimage图像处理(二)

    python skimage图像处理(二) This blog is from: https://www.jianshu.com/p/66e6261f0279  图像简单滤波 对图像进行滤波,可以有两 ...

  4. Java数组移位和统计

    package com.imooc.method; import java.util.InputMismatchException; import java.util.Scanner; public ...

  5. google cloud storage products

    https://cloud.google.com/products/storage/ BigTable Cloud Bigtable 是 Google 面向大数据领域的 NoSQL 数据库服务.它也是 ...

  6. Automl基于超大数据下的数据分发方案探讨

    先定义几个关键字: 任务:用户一次上传的数据集并发起的automl任务,比如一次ocr任务,一次图像分类任务. 模型:一次任务中,需要运行的多个模型,比如ocr任务,需要ctpn模型,需要crnn模型 ...

  7. 【APM】Pinpoint 使用教程(二)

    本例介绍Pinpoint使用教程 Pinpoint安装部署参考:[APM]Pinpoint 安装部署(一) 查看应用调用关系拓扑图 进入pintpoint->选择应用-〉选择查看的时间周期,即可 ...

  8. bootstrap datetimepicker 添加清空按钮

    <div class="ys-datetimepicker"> <input class="form-control" size=" ...

  9. linux 下mysql 关闭 启动

    一. 启动 .使用 service 启动:service mysql start .使用 mysqld 脚本启动:/etc/init.d/mysql start .使用 safe_mysqld 启动: ...

  10. maven:不再支持源选项 5。请使用 6 或更高版本。

    解决办法: 在pom.xml中添加maven的配置 <maven.compiler.source>11</maven.compiler.source> <maven.co ...