//----------------------------------------------------- // FastSleep.cpp // Hector Santos, Santronics Software, Inc. // http://www.santronics.com // email: sant9442@gmail.com // email: hsantos@santronics.com // // Utility to toggle the PC with Windows OS multi-media // resolution that speeds up the Sleep() quantum. // // All PC has a quantum of 10-15ms regardless of the // sleep value. Assuming the PC is 15ms, if you use // Sleep(1), the time slice is 15ms. Sleep(18) is 30ms, // and so on. // // This utility allows you to toggle the resolution // to 1 ms. The actual delay is shown by this utility. // // Why? // // This can change the behavior of your applications // which depends on timers, like many of the Web 2.0 // Javascript applications. In Windows, the multi media // function timeBeginPeriod() changes the resolution // for the entire system. So if some other application // is running with timeBeginPeriod(1) enabled, this // will have a drastic effect on your Web 2.0 application. // It may behave better, it may behave unexpected worst. // It might explain someone reported to you, "hey this // is not running right." But others don't see this, // and you can repeat it, so you just blew the report // away. This utility can be use to design your // application properly under all conditions. // // Command line compile with MSVC 6.0: // // cl fastsleep.cpp /W3 /GX /MD /D "_AFXDLL" // //----------------------------------------------------- #include #include #include #include #pragma comment(lib,"Winmm.lib") #define ThreadSleepTime 1 #define ThreadResolution 1 #define Iterations 100 /* METHOD0 - ave of start/finish sleep loop tics METHOD1 - ave of accumulated loop sleep tics METHOD2 - MM, ave of accumulated loop sleep timer METHOD3 - MM, ave of start/finish sleep loop timer */ #define METHOD2 #ifdef METHOD0 inline double method() { DWORD start=GetTickCount(); register i; for(i=0;i