首页 > 编程语言 >c# 计算程序执行时间,计算一段代码执行所用的时间,测试效率

c# 计算程序执行时间,计算一段代码执行所用的时间,测试效率

时间:2023-04-27 17:05:50浏览次数:38  
标签:count c# System long 程序执行 QueryPerformanceCounter heisetoufa 代码执行 ref


using System;
using System.Threading;
class Class1
{
	[System.Runtime.InteropServices.DllImport("Kernel32.dll")]
	static extern bool QueryPerformanceCounter(ref long count);
	[System.Runtime.InteropServices.DllImport("Kernel32.dll")]
	static extern bool QueryPerformanceFrequency(ref long count);
	[STAThread]
	static void Main(string[] args)
	{
		long count = 0;
		long count1 = 0;
		long freq = 0;
		double result = 0;
		QueryPerformanceFrequency(ref freq);
		QueryPerformanceCounter(ref count);
		//需要测试的模块

		int heisetoufa;
		for (heisetoufa = 1; heisetoufa < 10000; heisetoufa++)
		{
			Console.WriteLine("第" + heisetoufa + "行");
			if (heisetoufa == 5000)
			{
				Thread.Sleep(10000);
			}
		}

		//需要测试的模块

		QueryPerformanceCounter(ref count1);
		count = count1 - count;
		result = (double)(count) / (double)freq;
		Console.WriteLine("耗时: {0} 秒", result);
		Console.ReadLine();
	}
}




黑色头发:http://heisetoufa.iteye.com/


标签:count,c#,System,long,程序执行,QueryPerformanceCounter,heisetoufa,代码执行,ref
From: https://blog.51cto.com/u_2543512/6231818

相关文章

  • 查询出数据库中char型字段的最大值,查出数据库中字段最大值,max,缺少列,xh...
    SELECTmax(cast(xhasint))asxhFROMkk.kkcltj用cast(xhasint)把varchar(2)的类型转成int后再查出最大值注意:xh的字段里只能存储char型或number型数据,否则会报无效符号错误有时候不主意会写成SELECTmax(cast(xhasint))FROMkk.kkcltj这样select出来的值就没有......
  • java 后台给前台传值,html:select,html:text等加载页面显示默认值的方法
    后台写request.setAttribute("dateCreated","黑色头发");前台接收:html:text<html:textproperty="dateCreated"value="${dateCreated}"/>html:select<html:selectproperty="accountsUser"va......
  • java js JavaScript 设置html:radio的默认选中, js也可以用el表达式
    <html:radioproperty="consumptionClass"value="花了">花了</html:radio><html:radioproperty="consumptionClass"value="赚了">赚了</html:radio><html:radioproperty="consumptionClass"va......
  • equal symbol expected
    这样嵌套会异常<html:textproperty="dateCreated"value=<bean:writename="dateCreated"property="dateCreated"/>/>像下边这样写就不会<html:textproperty="dateCreated"value="${dateCreated......
  • c# winform 用代码生成一张只有一个像素点的图片,保存到硬盘里或者显示到panel里...
    只生成图片stringnullPath="C:\\黑色头发.jpg";Bitmapb=newBitmap(1,1);b.Save(nullPath);b.Dispose();生成图片并显示到panel里Bitmapb=newBitmap(this.panel1.Width,this.panel1.Height);this.panel1.DrawToBitmap(b,newRectangle(0......
  • abstract class和interface有什么区别?
    声明方法的存在而不去实现它的类被叫做抽象类(abstractclass),它用于要创建一个体现某些基本行为的类,并为该类声明方法,但不能在该类中实现该类的情况。不能创建abstract类的实例。然而可以创建一个变量,其类型是一个抽象类,并让它指向具体子类的一个实例。不能有抽象构造函数或抽象静......
  • GC垃圾回收机制,垃圾回收,垃圾收集器
    GC是垃圾收集器。Java程序员不用担心内存管理,因为垃圾收集器会自动进行管理。但是要请求垃圾收集,可以调用下面的方法之一:System.gc()Runtime.getRuntime().gc() 黑色头发 http://heisetoufa.iteye.com如果发现本文有误,欢迎批评指正......
  • 垃圾回收机制,如何优化程序?GC
    垃圾回收是由jvm控制的,我们不能控制jvm进行垃圾回收  为了优化程序我们所能做的就是把我们不需要的资源处理成符合jvm垃圾回收条件  例如  Integer i=new Integer(88);  ...  //这时候我们不需要这个类了,我们希望jvm尽早进行垃圾回收,那么。。  ......
  • sql.SQLException: 对只转发结果集的无效操作: absolute,可滚动结果集
    获得ResultSet的长度可以使用getRow,但是首先要设置ResultSet为可滚动结果集,否则会报java.sql.SQLException:对只转发结果集的无效操作:absolute设置方法为Statement 的设置方法:Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_O......
  • distinct,sql语句去掉重复值,去掉重复值
    感谢老紫竹群中joejoe1991帮助selectdistinctdwfromkk.kkyh这条语句查出来的dw是没有重复值的 黑色头发 http://heisetoufa.iteye.com如果发现本文有误,欢迎批评指正......