C# 计时程序运行时间
第一种 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# 计时程序运行时间的更多相关文章
- python 计时程序运行时间
import time time_start=time.time() time_end=time.time() print('totally cost',time_end-time_start)
- VC中监测程序运行时间(二)-毫秒级
/* * 微秒级计时器,用来统计程序运行时间 * http://blog.csdn.net/hoya5121/article/details/3778487#comments * //整理 [10/1 ...
- VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...
- VC++程序运行时间测试函数
0:介绍 我们在衡量一个函数运行时间,或者判断一个算法的时间效率,或者在程序中我们需要一个定时器,定时执行一个特定的操作,比如在多媒体中,比如在游戏中等,都会用到时间函数.还比如我们通过记录函数或者算 ...
- C++程序运行时间-ZZ
[15.5.25]贴一段实用的代码,linux下跑过. #include <stdio.h> /* printf */ #include <time.h> /* clock_t ...
- VC程序运行时间测试函数
VC程序运行时间测试函数 介绍 我们在衡量一个函数运行时间,或者判断一个算法的时间效率,或者在程序中我们需要一个定时器,定时执行一个特定的操作,比如在多媒体中,比如在游戏中等,都会用到时间函数.还比如 ...
- 【VS开发】VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...
- 检测Java程序运行时间的2种方法(高精度的时间[纳秒]与低精度的时间[毫秒])
第一种是以毫秒为单位计算的. 代码如下: long startTime=System.currentTimeMillis(); //获取开始时间 doSomeThing(); //测试的代码段 lon ...
- PAT乙级 1026. 程序运行时间(15)
1026. 程序运行时间(15) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 要获得一个C语言程序的运行时间, ...
随机推荐
- iptables 限制端口
限制端口 #!/bin/bashiptables -P INPUT ACCEPTiptables -P OUTPUT ACCEPTiptables -Fiptables -P INPUT DROPip ...
- 论文阅读 | Recurrent Attentional Reinforcement Learning for Multi-label Image Recognition
源地址 arXiv:1712.07465: Recurrent Attentional Reinforcement Learning for Multi-label Image Recognition ...
- Java 内存排查,慢慢收集总结
Java堆外内存排查小结: https://mp.weixin.qq.com/s?__biz=MzA4MTc4NTUxNQ==&mid=2650518612&idx=2&sn= ...
- 使用Sabaki和Leela Zero配置AI围棋对弈环境
求 李昌镐儿童围棋课堂 的pdf. 一.下载Sabaki和Leela Zero最新版本 二.安装Sabaki 三.安装leela zero 四.Sabaki配置leela zero引擎 五.Sabak ...
- gcc 编译两个so其中soA依赖soB
有两个so,其中soB中调用soA: 那么我们打包soB的时候连接soA: 在打包test程序的时候连接soB,此时soB会自动查找依赖的soA: 如下测试 在编译之前指定环境变量:export LD ...
- windows server core 2016 IIS远程管理的那些坑
打算从win10访问数据中心版2016 core,结果IIS远程管理不了. 需要修改core上防火墙和注册表,开启一些相关服务. 具体需要如下操作. 1.win10 启用IIS管理特性 2.参考htt ...
- 006-tomcat 多实例安装、appBase和docBase、Context说明
一.多实例部署 主要是为了充分利用服务器资源,并且可以交叉部署应用.主要做法可以有使用docker部署,多实例部署. 多实例多应用:多个 Tomcat 部署多个不同的项目.这种模式在服务器资源有限,或 ...
- 转 RAC单个节点执行expdp提示ORA-31693 ORA-31617 ORA-19505 ORA-27037错误
http://blog.itpub.net/31394774/viewspace-2217567/ 1.在RAC单节点执行expdp,出现ORA-31693 ORA-31617 ORA-19505 O ...
- MySQL创建触发器的时候报1419错误( 1419 - You do not have the SUPER privilege and binary logging is enabled )
mysql创建触发器的时候报错: 解决方法:第一步,用root用户登录:mysql -u root -p第二步,设置参数log_bin_trust_function_creators为1:set gl ...
- spark + hive
1.如何让 spark-sql 能够访问hive? 只需将hive-site.xml 放到 spark/conf 下即可,hive-site.xml 内容请参照hive集群搭建 2.要在spark 代 ...