C#测试用计算程序执行时间
2010-04-12 15:01
417 查看
using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace MyTimeCost { class Program { [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 < 100; heisetoufa++) { //Console.WriteLine("第" + heisetoufa + "行"); if (heisetoufa == 5000) { Thread.Sleep(10); } } //需要测试的模块 QueryPerformanceCounter(ref count1); count = count1 - count; result = (double)(count) / (double)freq; Console.WriteLine("耗时: {0} 秒", result); Console.ReadLine(); } } }
相关文章推荐
- Linux 精准计时-暨计算程序或函数执行的时间
- 用C#计算程序执行的时间间隔
- php 计算程序的执行时间
- c# 计算程序执行时间
- 使用QueryPerformanceFrequency 计算程序执行时间
- php计算当前程序执行时间示例
- php使用microtime(true)计算php程序代码执行消耗时间
- 计算程序执行时间的方法
- Linux 精准计时-暨计算程序或函数执行的时间
- 一个计算程序执行时间的批处理
- java 计算程序执行时间
- java程序执行时间计算
- linux下的C语言计算程序执行时间
- 三步计算php程序执行时间
- C#:程序控制--计算程序执行耗费的时间
- 使用QueryPerformanceFrequency 计算程序执行时间
- 用C#计算程序执行的时间间隔
- c与java中计算程序执行时间的方法
- C# TimeSpan类计算程序执行的时间及此类的其他常用方法
- C语言中,计算程序执行时间的经典例子