GetMicrosecondCount 
Hàm GetMicrosecondCount() trả về số micro giây đã trôi qua kể từ khi chương trình MQL5 khởi động.
cpp
ulong  GetMicrosecondCount();1
Giá trị trả về
Giá trị kiểu ulong.
Ví dụ:
cpp
//+------------------------------------------------------------------+
//| Hàm kiểm tra                                                    |
//+------------------------------------------------------------------+
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++;
     }
  }
//+------------------------------------------------------------------+
//| Hàm khởi động chương trình script                               |
//+------------------------------------------------------------------+
void OnStart()
  {
   uint   ui=0,ui_max=0,ui_min=INT_MAX;
   ulong  ul=0,ul_max=0,ul_min=INT_MAX;
   //--- số lần đo
   for(int count=0;count<1000;count++)
     {
      uint  ui_res=0;
      ulong ul_res=0;
      //---
      for(int n=0;n<2;n++)
        {
         //--- chọn loại đo
         if(n==0) ui=GetTickCount();
         else     ul=GetMicrosecondCount();
         //--- thực thi mã
         Test();
         //--- thêm kết quả đo (tùy thuộc vào loại)
         if(n==0) ui_res+=GetTickCount()-ui;
         else     ul_res+=GetMicrosecondCount()-ul;
        }
      //--- tính toán thời gian tối thiểu và tối đa cho cả hai phép đo
      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("Sai số GetTickCount (msec): ",ui_max-ui_min);
   Print("Sai số GetMicrosecondCount (msec): ",DoubleToString((ul_max-ul_min)/1000.0,2));
  }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Xem thêm
