快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

.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);

UInt64 cpuspeed10=(ulong)(timer.Stop()/100000); //通过这个可以算出 CPU 的mhz

timer.Start();//开始

//测试代码(测试声明一个DataTable 用的时间)

DataTable td= new DataTable();

UInt64 time1=timer.Stop();//停止

String s= String.Format("CPU {0}.{1} mhz/n声明 MLTimer 类的系统开销 {2:n} 时钟周期/n本操作系统开销 {3:n} 个时钟周期/n使用 {4:n} ns",

cpuspeed10/10,cpuspeed10%10,timer.Overhead,

time1,

time1*10000/cpuspeed10);

MessageBox.Show(s);

}

/*-------------------------------------------------------------------------------------------





返回类别: 教程
上一教程: Microsoft .NET,第三代的因特网平台(转)
下一教程: asp.net 的 Request对象

您可以阅读与".Net 实现纳秒级别计算"相关的教程:
· 在 Visual Basic .NET 中实现后台进程(一)
· .net Compact Flamework中MD5CryptoServiceProvider的实现
· ASP.NET实现用户在线检测的类源码
· 刚学ASP.Net,学了个简朴的计算器
· 使用.net Remtoing进行并行计算
    微笑服务 优质保证 索取样品