Функциональный тест Sleep()

 
Я нашел функцию Sleep() не работаю точно как предположено.
См. таблицу для результатов испытаний.
Испытание к Sleep() от 0 к 99 миллисекундам и пользе GetTickCount() увидеть сколько времени сон продолжал.
Результаты могли поменять с по-разному чомпьютерной аппаратурой.
Заключения:
Это будет вероятно ограничение os and/or оборудования. Sleep() происходит на способе hit/miss на йьмиллисечонд границах не полагается на Sleep() для того чтобы быть точно, и не полагается на значениях более менее чем 16 миллисекунд.
Кодий испытания для того чтобы собрать данные:
Сценарий требует немного минут к бегу, прогрессу монитора (0-99) в стержне
... I wonder what all that says !
------------------------------------------------------------------------
Original English:

I found the Sleep() function does not work exactly as expected.

See the table for test results. The test is to Sleep() from 0 to 99 milliseconds and use GetTickCount() to see how long the sleep lasted.

Results might vary with different PC hardware.

Conclusions:
This is probably OS and/or hardware limitation.
Sleep() occurs on a hit/miss fashion on 16millisecond boundaries
Don't rely on Sleep() to be exact, and don't rely on values less than 16 milliseconds.

Test code to collect data:
The script takes a few minutes to run, monitor progress (0-99) in the terminal

int start()
  {
    string result[100][50];    
    int i, j;
    int startTick, endTick;    
    for( i = 0; i < 100; i++){
        Print(i);
        for(j = 0; j < 50; j++){
            startTick = GetTickCount();
            Sleep(i);
            endTick = GetTickCount();
            result[i][j] = DoubleToStr(endTick - startTick, 0)+" ";
        }
    }
    int FILE;
    FILE = FileOpen("SleepTest.txt", FILE_WRITE|FILE_BIN);    
    string resultLine;
    for(i = 0; i < 100; i++){
        resultLine = "Sleep("+i+") GetTickCount() = ";
        for(j = 0; j < 50; j++){
            resultLine = StringConcatenate(resultLine, result[i][j], " ");
        }
        resultLine = StringConcatenate(resultLine, "\r\n");    
        FileWriteString(FILE, resultLine, StringLen(resultLine));
    }
   return(0);
  }
Образец spreadsheet, значения в миллисекундах как сообщено МТЯ
Файлы:
sleeptest_1.zip  11 kb
 

1. Функция GetTickCount не может быть использована для точного определения маленьких интервалов. Вы можете получить 0 мс, 16 мс, 1034 мс... Но от 1 до 14 мс Вы не получите никогда. Особенности архитектуры.

2. Функция Sleep работает не совсем так, как многие думают. На самом деле система гарантирует, что Sleep(1) займет НЕ МЕНЬШЕ 1ms, а верхний предел не лимитируется. (цитата из статьи "То, что вам никто не говорил о многозадачности в Windows")

3. Функция Sleep в клиентском терминале работает с грануляцией 100 мс, для того чтобы нельзя было завесить советника.

1. Function GetTickCount cannot be used for exact detection of small intervals. You may get 0 ms, 16 ms, 1034 ms, etc. However, you will never get 1-14 ms. This is due to architecture properties.

2. Function Sleep works in a bit different way than many people think. Indeed, the system guarantees that Sleep(1) will take AS MUCH AS 1ms, whereas the upper limit is not specified. (Quoted from the article "То, что вам никто не говорил о многозадачности в Windows" in Russian, translated into English by myself, sorry. This may sound like 'What You Have Never Been Told about Multitasking in Windows')

3. Function Sleep in the client terminal works with granulation of 100 ms in order one not to be able to hang the Expert Advisor.