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语言程序的运行时间, ...
随机推荐
- salt-master命令详解
**salt-master命令** 命令行官网学习网站:http://docs.saltstack.cn/ref/cli/index.html salt salt-call salt-cp salt- ...
- Python快速入门教程【转】
第一章 Python基础知识 1.1 介绍 1.1.1 特点 Python是一种面向对象.解释型计算机程序设计语言.语法简洁清晰,强制用空白符作为语句缩进. Python ...
- iOS逆向必备绝技之ipa重签名
一.重签名准备工作: 找到开发者证书和配置文件: 列出所有开发者证书文件: security find-identity -p codesigning -v 找一个开发环境配置文件生成entitlem ...
- win10下通过编译源码方式在chrome中成功安装react-devtools开发工具插件
win10下通过编译源码方式在chrome中成功安装react-devtools开发工具插件 1.去git上下载react-devtools文件到本地,https://github.com/fac ...
- Create table as select
create table xxx as select create table table1 =; 根据table2的表结构,创建tables1 create table table1 as sele ...
- Cassandra3在Centos7下启动失败解决办法
Centos7 安装Cassandra启动过程提示失败,查看结果如下所示: [root@xx ~]# systemctl status cassandra ● cassandra.service - ...
- windows zip命令
针对 Windows 用户的提示: win不自带zip,因此 Windows 用户可以从 GnuWin32 项目页面 上下载zip ,并将 C:\Program Files\GnuWin32\bin( ...
- MySQL高效分页-mybatis插件PageHelper改进
MySQL分页在表比较大的时候,分页就会出现性能问题,MySQL的分页逻辑如下:比如select * from user limit 100000,10 它是先执行select * from user ...
- 关于阿里云 RDS mysql索引优化的一点经验
2019年9月5日10:02:34 本地调试 git https://github.com/barryvdh/laravel-debugbar composer require barryvdh/la ...
- Centos7时区修改方法汇总
方法一: timedatectl set-timezone Asia/Shanghai 方法二: 设置环境变量TZ(这个方法用得比较少,但是有一次就是这个方法帮了我大忙,其他都无法实现修改时区,特此记 ...