C# 统计程序执行时间
随便写写,小马哥勿怪
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来。
十年河东十年河西,莫欺少年穷。
话说马云年轻的时候也是屌丝一枚,有图为证
现在的马云依然是亚洲首富啊(有图为证),所以嘛,十年河东十年河西,莫欺少年穷。
以上均是开玩笑,希望小马哥别生气哦
C#统计程序执行时间,代码如下:
class Program
{ static void Main(string[] args)
{
string s = "chen";
string ss = "chen";
Stopwatch sw = new Stopwatch();
sw.Start(); for (int i = ; i < ; i++)
{
if (s == ss)
{
//Console.WriteLine("字符串相同");
}
else
{
//Console.WriteLine("字符串不相同");
} }
sw.Stop();
TimeSpan ts2 = sw.Elapsed;
Console.WriteLine("sw总共花费{0}ms.", ts2.TotalMilliseconds); Stopwatch sw_Eq = new Stopwatch();
sw_Eq.Start(); for (int i = ; i < ; i++)
{
if (s.Equals(ss))
{
//Console.WriteLine("字符串相同");
}
else
{
//Console.WriteLine("字符串不相同");
} }
sw_Eq.Stop();
TimeSpan tssw_Eq = sw_Eq.Elapsed;
Console.WriteLine("sw_Eq总共花费{0}ms.", tssw_Eq.TotalMilliseconds); Console.ReadKey();
} }
当然,咱们也可以自行写一个方法,很简单的,就是程序执行前,统计下当前时间,执行完成后,统计下当前时间,两个当前时间相减即可
代码如下:
class Program
{ static void Main(string[] args)
{
string s = "chen";
string ss = "chen";
Stopwatch sw = new Stopwatch();
sw.Start(); for (int i = ; i < ; i++)
{
if (s == ss)
{
//Console.WriteLine("字符串相同");
}
else
{
//Console.WriteLine("字符串不相同");
} }
sw.Stop();
TimeSpan ts2 = sw.Elapsed;
Console.WriteLine("sw总共花费{0}ms.", ts2.TotalMilliseconds); Stopwatch sw_Eq = new Stopwatch();
sw_Eq.Start(); for (int i = ; i < ; i++)
{
if (s.Equals(ss))
{
//Console.WriteLine("字符串相同");
}
else
{
//Console.WriteLine("字符串不相同");
} }
sw_Eq.Stop();
TimeSpan tssw_Eq = sw_Eq.Elapsed;
Console.WriteLine("sw_Eq总共花费{0}ms.", tssw_Eq.TotalMilliseconds); DateTime beforDT = System.DateTime.Now; for (int i = ; i < ; i++)
{
if (s.Equals(ss))
{
//Console.WriteLine("字符串相同");
}
else
{
//Console.WriteLine("字符串不相同");
} } DateTime afterDT = System.DateTime.Now;
TimeSpan ts = afterDT.Subtract(beforDT);
Console.WriteLine("DateTime总共花费{0}ms.", ts.TotalMilliseconds); Console.ReadKey();
}
}
执行结果图如下:
@陈卧龙的博客
C# 统计程序执行时间的更多相关文章
- c语言统计程序执行时间
c语言程序执行时间 #include <iostream> #include <cstdio> #include <ctime> int main() { std: ...
- 如何通过Java8的方式去统计程序执行时间?
代码如下所示 import java.time.Duration; import java.time.Instant; import java.util.concurrent.TimeUnit; pu ...
- Spring AOP实例——异常处理和记录程序执行时间
实例简介: 这个实例主要用于在一个系统的所有方法执行过程中出线异常时,把异常信息都记录下来,另外记录每个方法的执行时间. 用两个业务逻辑来说明上述功能,这两个业务逻辑首先使用Spring AOP的自动 ...
- c++英文单词频度统计程序
英文单词频度统计程序(c++版) 写一个程序,分析一个文本文件(英文文章)中各个次出现的频率,并且把频率最高的十个词打印出来. 分析过程: (1) 简单设想大致分为两大步骤: 1.经过文本文件的读操 ...
- CodeIgniter框架开发的统计程序源代码开放
文章来源: PHP开发学习门户 自己初学php时,用CodeIgniter框架开发的后台统计程序源代码 程序部分页面如图: 具体配置及下载源代码:http://bbs.phpthinking.com/ ...
- java查看程序执行时间
public static void main(String[] args) { long a= System.currentTimeMillis();//获取当前系统时间(毫秒) for (int ...
- Mapreduce的序列化和流量统计程序开发
一.Hadoop数据序列化的数据类型 Java数据类型 => Hadoop数据类型 int IntWritable float FloatWritable long LongWritable d ...
- php 测试 程序执行时间,内存使用情况
memory_get_usage 可以分析内存占用空间. microtime 函数就可以分析程序执行时间. 上栗子: echo '开始内存:'.memory_get_usage(), ''; $tmp ...
- “人向猿进阶”之软件工程第三课----WORDCOUNT.EXE统计程序
---恢复内容开始--- WC项目要求 这个项目要求写一个命令行程序,模仿已有的wc.exe的功能,并加以扩充,给出某程序设计源语言文件的字符数.单词数和行数.给实现一个统计程序,它能正确统计程序文件 ...
随机推荐
- Unix时间戳(Unix timestamp)转换工具
http://tool.chinaz.com/Tools/unixtime.aspx 现在的Unix时间戳(Unix timestamp)是 1440732364 Unix时间戳( ...
- 高手指南PHP安装配置
高手指南PHP安装配置 2014-11-05 12:57:13 来源: 评论:0 次 点击:12 次 | 发布人:登陆查看 PHP的快速发展,它的功能越来越强大,运用它也变得很方便,下面我 ...
- 【IOS笔记】View Controller Basics
View Controller Basics 视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ...
- software glue Middleware
https://en.wikipedia.org/wiki/Middleware https://zh.wikipedia.org/wiki/中间件 Middleware is computer so ...
- Blender to XPS(blender 2.7x Internal materials)
Things we are gonna need are Blender 2.7x www.blender.org/ XPS tools addon for Blender A model made ...
- SQL查询一周内过生日的用户
SELECT birthday, )) + '-' + )) + '-' + )) AS datetime) AS Nbirthday FROM CRM_Customer WHERE birthday ...
- Redis-分布式
package test.jedis; import java.util.HashSet; import java.util.Set; import org.junit.Test; import re ...
- js合计
Js合计行: 可以先循环行,然后按行获取这行带有你定义的class的td,取得这些td的 text后相加,最终赋值到这行的“合计”单元格就行了 var trslength = $("#dat ...
- iOS开发教程之:iPhone开发环境搭建
安装条件: 硬件:一台拥有支持虚拟技术的64位双核处理器和2GB以上内存的PC. 注意:运行MAC OS,需要电脑支持虚拟技术(VT),安装时,需要将VT启动,在BIOS中开启. 软件: Window ...
- How to Move Magento to a New Server or Domain
Magento is one of the fastest growing eCommerce platforms on the internet and with its recent acquis ...