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

推荐订阅源

Google DeepMind News
Google DeepMind News
D
Docker
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
月光博客
月光博客
小众软件
小众软件
量子位
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
罗磊的独立博客
博客园 - 叶小钗
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
C
Check Point 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);
   }
  }