High-Performance Timer in C#
来源:互联网 发布:怎么看有没有网络监控 编辑:程序博客网 时间:2024/04/27 14:43
继上一篇 http://blog.csdn.net/Joyhen/article/details/17222273
原文:http://www.codeproject.com/Articles/2635/High-Performance-Timer-in-C
上码:
namespace ConsoleApplication1{ using System; using System.Runtime.InteropServices; using System.ComponentModel; using System.Threading; internal class HiPerfTimer { const string dll = "Kernel32.dll"; [DllImport(dll)] private static extern bool QueryPerformanceCounter(out long lpPerformanceCount); [DllImport(dll)] private static extern bool QueryPerformanceFrequency(out long lpFrequency); private long startTime, stopTime; private long freq; // Constructor public HiPerfTimer() { startTime = 0; stopTime = 0; if (QueryPerformanceFrequency(out freq) == false) { // high-performance counter not supported throw new Win32Exception(); } } // Start the timer public void Start() { // lets do the waiting threads there work Thread.Sleep(0); QueryPerformanceCounter(out startTime); } // Stop the timer public void Stop() { QueryPerformanceCounter(out stopTime); } // Returns the duration of the timer (in seconds) public double Duration { get { return (double)(stopTime - startTime) / (double) freq; } } }}使用:
static void Main(string[] args) { HiPerfTimer pt = new HiPerfTimer(); pt.Start(); var items = Guid.NewGuid(); Console.WriteLine(items.ToString()); pt.Stop(); Console.WriteLine("Duration: {0} sec\n", pt.Duration); Console.ReadKey(); }
1 0
- High-Performance Timer in C#
- How to write the fast code/ high performance in C#
- Topics in High-Performance Messaging
- High performance models in TensorFlow
- Versatile High Performance Hierarchies in SQL Server
- Implementing High Performance Parsers in Java
- How to Write High-Performance C# Code
- High performance
- performance optimization in C#
- High Performance Computing in Science and Engineering ' 05 : Transactions of the High Performance Co
- Timer in C#
- High Performance MySQL
- Leading High-Performance Projects
- High performance network programming
- High Performance Computer Architecture
- Build High performance Server
- High performance MySQL-- 笔记
- High-Performance Server Architecture
- hdoj.1272 小希的迷宫【并查集】 2015/07/23
- 初学c++,释放动态数组内存出现的问题解决
- 图像处理------相似图片识别(直方图应用篇)
- 搞ACM的伤不起 真是说的要好了
- windows环境下SVN服务器限制注释字数
- High-Performance Timer in C#
- mysqlbinlog的日志类型
- LintCode - Add Two Numbers
- JSTL
- 算法问题总结
- 代理
- [前端] JS字符串过滤
- uep开发——财务管理系统的总结
- 14个Xcode中常用的快捷键操作