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

推荐订阅源

博客园 - 叶小钗
MyScale Blog
MyScale Blog
博客园 - 【当耐特】
I
InfoQ
腾讯CDC
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
人人都是产品经理
人人都是产品经理
D
DataBreaches.Net
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Vercel News
Vercel News
C
Check Point Blog
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
D
Docker
MongoDB | Blog
MongoDB | 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);
   }
  }