惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
有赞技术团队
有赞技术团队
博客园 - 三生石上(FineUI控件)
博客园_首页
博客园 - 【当耐特】
WordPress大学
WordPress大学
月光博客
月光博客
博客园 - 叶小钗
S
SegmentFault 最新的问题
雷峰网
雷峰网
H
Help Net Security
宝玉的分享
宝玉的分享
A
About on SuperTechFans
IT之家
IT之家
J
Java Code Geeks
Hugging Face - Blog
Hugging Face - Blog
D
DataBreaches.Net
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
T
The Blog of Author Tim Ferriss
B
Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Y
Y Combinator Blog

博客园 - trylazy

oracle 共享服务器 专用服务器 SQLPlus 点滴 oracle初始化参数 Oracle 学习记录 oracle的Bug? 存取器不是参数存取器 C# Equals 与 == 程序的易用性 dcom 终端 多个实例 Oracle 错误 asp.net 超时 asp.net 重启 数据库表设计 根据机器名不能访问 C# WinForm .net Drag Drop NULL SQL Server Oracle 更改Delphi 中ClientDataSet中字段的数据类型 VS.net在打开窗体设计器时报错 安装程序检测到另一个程序要求计算机重启 Log4net使用注意
高精度计数 .net 1.1
trylazy · 2005-12-21 · via 博客园 - trylazy

.net 2.0中存在一个高精度的计数器StopWartch,
但.net 1.1中却不存在这个计数,可以使用Win32API来模拟这个类,如下:

public class StopWatch
  {
   [DllImport("KERNEL32")]
   private static extern bool QueryPerformanceCounter(
    out long lpPerformanceCount);

   [DllImport("Kernel32.dll")]
   private static extern bool QueryPerformanceFrequency(out long lpFrequency);

   private long start;
   private long stop;
   private long frequency;
   Decimal multiplier = new Decimal(1.0e9);

   public StopWatch()
   {
    if (QueryPerformanceFrequency(out frequency) == false)
    {
     throw new Exception("Frequency not supported");
    }
   }

   public void Start()
   {
    QueryPerformanceCounter(out start);
   }

   public void Stop()
   {
    QueryPerformanceCounter(out stop);
   }

   public double Duration(int iterations)
   {
    return ((((double)(stop - start)* (double) multiplier) / (double) frequency)/iterations);
   }
  }