第一种   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. Guava Cache 缓存实现与源码分析

    目录 一.概述 1.内存缓存 2.核心数据结构 二.具体实现 0.一览众山小 1.CacheBuilder 构建器 2.LocalCache 一.概述 1.内存缓存 可看作一个jdk7的concurr ...

  2. FZU Monthly-201906 tutorial

    FZU Monthly-201906 tutorial 题目(难度递增) easy easy-medium medium medium-hard hard 思维难度 AE B DG CF H A. X ...

  3. 【Alpha】“北航社团帮”小程序v1.0测试报告

    目录 测试计划.过程和结果 后端单元测试 后端压力测试 测试结果 指标解释 前端测试 授权登录与权限检查 功能测试 兼容性测试 性能测试 回答课程组问题 测试中发现的bug 场景测试 测试矩阵 出口条 ...

  4. Spring Boot集成Mybatis注解相关

    mybatis3开始支持java注解,使用java注解可以替代xml配置文件,简化代码.下面来看一下怎么在spring boot中使用mybatis注解. 1 使用mybatis注解需要的配置.如下面 ...

  5. 如何将业务代码写得像诗一样(使用注解+单例+工厂去掉一大波if和else判断)

    1.订单控制器,提供一个根据商品id和银行渠道id计算商品折后价格的接口: import org.springframework.web.bind.annotation.GetMapping; imp ...

  6. 使用CompletableFuture实现业务服务的异步调用实战代码

    假如我有一个订单相关的统计接口,需要返回3样数据:今日订单数.今日交易额.总交易额. 一般的我们的做法是串行调用3个函数,把调用返回的结果返回给调用者,这3次调用时串行执行的,如果每个调用耗时1秒的话 ...

  7. debian8 vga 文本模式下出现闪屏

    这种问题是因为 grub 里面关于 分辨率大小不对的问题. 在 debian 里面,在文件 /boot/grub/grub.cfg 里面可以添加 vga 参数配置. 如下: 在 kernel 启动参数 ...

  8. 词向量 词嵌入 word embedding

    词嵌入 word embedding embedding 嵌入 embedding: 嵌入, 在数学上表示一个映射f:x->y, 是将x所在的空间映射到y所在空间上去,并且在x空间中每一个x有y ...

  9. org.apache.hadoop.fs.FsUrlStreamHandlerFactory 在哪个jar包

    org.apache.hadoop.fs.FsUrlStreamHandlerFactory在org.apache.hadoop类中,org.apache.hadoop在hadoop安装目录下.

  10. 【翻译】Flink Table Api & SQL — 配置

    本文翻译自官网:Configuration https://ci.apache.org/projects/flink/flink-docs-release-1.9/dev/table/config.h ...