当前位置:编程学习 > C#/ASP.NET >>

.Net 实现纳秒级别计算

Net 实现纳秒级别计算
1)建立VC.NET 托管类库
using namespace System;
namespace MLTimerDot
{
//得到计算机启动到现在的时钟周期
unsigned __int64 GetCycleCount(void)
{
_asm _emit 0x0F
_asm _emit 0x31
}
//声明 .NET 类
public __gc class MLTimer
{
protected:
UInt64 m_startcycle;
UInt64 m_overhead;
public:
MLTimer(void)
{
//为了计算更精确取得调用一个 GetCycleCount() 的时钟周期
m_overhead=0;
Start();
m_overhead=Stop();
}
//计算停止
UInt64 Stop(void)
{
return GetCycleCount()-m_startcycle-m_overhead;
}
//计算开始
void Start(void)
{
m_startcycle=GetCycleCount();
}
__property virtual UInt64 get_Overhead()
{
return m_overhead;
}
};
}
2)测试代码
//C# 引用后放一个Button 测试
private void button1_Click(object sender, System.EventArgs e)
{
MLTimerDot.MLTimer timer=new MLTimerDot.MLTimer();
timer.Start();
Thread.Sleep(1000);
补充:asp.net教程,基础入门 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,