GetMicrosecondCount

GetMicrosecondCount() 函数返回MQL5程序开始后过去的微秒数。

ulong  GetMicrosecondCount();

返回值

无符号长整型的值。

示例:

//+------------------------------------------------------------------+

//| 测试函数                                                          |

//+------------------------------------------------------------------+

void Test()

  {

   int    res_int=0;

   double res_double=0;

//---  

   for(int i=0;i<10000;i++)

     {

      res_int+=i*i;

      res_int++;

      res_double+=i*i;

      res_double++;

     }

  }

//+------------------------------------------------------------------+

//| 脚本程序开始函数                                                   |

//+------------------------------------------------------------------+

void OnStart()

  {

   uint   ui=0,ui_max=0,ui_min=INT_MAX;

   ulong  ul=0,ul_max=0,ul_min=INT_MAX;

//--- 测量次数

   for(int count=0;count<1000;count++)

     {

      uint  ui_res=0;

      ulong ul_res=0;

      //--- 

      for(int n=0;n<2;n++)

        {

         //--- 选择测量类型

         if(n==0) ui=GetTickCount();

         else     ul=GetMicrosecondCount();

         //--- 执行代码 

         Test();

         //--- 添加测量结果 (根据类型)

         if(n==0) ui_res+=GetTickCount()-ui;

         else     ul_res+=GetMicrosecondCount()-ul;

        }

      //--- 为两个测量计算最小和最大的时间值

      if(ui_min>ui_res) ui_min=ui_res;

      if(ui_max<ui_res) ui_max=ui_res;

      if(ul_min>ul_res) ul_min=ul_res;

      if(ul_max<ul_res) ul_max=ul_res;

     }

//---

   Print("GetTickCount error(msec): ",ui_max-ui_min);

   Print("GetMicrosecondCount error(msec): ",DoubleToString((ul_max-ul_min)/1000.0,2));

  }

另见

日期和时间, GetTickCount, GetTickCount64