{"id":818,"date":"2008-05-29T16:04:08","date_gmt":"2008-05-29T16:04:08","guid":{"rendered":"http:\/\/6teen.ru\/?p=568"},"modified":"2008-05-29T16:04:08","modified_gmt":"2008-05-29T16:04:08","slug":"5110","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=818","title":{"rendered":"\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430: \u041a\u0430\u043a \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e Windows"},"content":{"rendered":"<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430: \u041a\u0430\u043a \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e Windows<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430: \u041a\u0430\u043a \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e Windows\n\n\u041a\u043e\u043b\u043e\u0431\u043e\u043a\n17.11.2005, 11:45\n\u041f\u043e \u0432\u043e\u043b\u0435 \u0441\u043b\u0443\u0447\u0430\u044f, \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u044f \u043e\u0434\u043d\u0443 \u043f\u0440\u043e\u0433\u0443, \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 Windows. \u041f\u043e \u044d\u0442\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0430 \u0414\u0435\u043b\u0444\u0438.\n\nprogram PerfCounter;\n\n{$APPTYPE CONSOLE}\n\nuses\nWindows,\nSysUtils;\n\nconst\nMAX_ATTEMPTS = 32;\n\ntype\nTPerfData = record\nPerfStart, PerfEnd, PerfFreq, PerfDelta: Int64;\nTSCStart, TSCEnd, TSCDelta: Int64;\nMhz: Cardinal;\nend;\n\n\/\/ Read TSC Counter\nfunction RDTSC():Int64;assembler;\nasm\nrdtsc;\nend;\n\nvar\nPerfData: array [0..MAX_ATTEMPTS] of TPerfData;\nIndex: Cardinal;\nAverage: Cardinal;\nbegin\nIndex := 0;\nwhile true do\nbegin\n\n\/\/\n\/\/ Collect a new sample\n\/\/ Delay the thread a \"long\" amount and time it with\n\/\/ a time source and RDTSC.\n\/\/\n\nQueryPerformanceCounter(PerfData.PerfStart);\nPerfData.TSCStart := RDTSC();\nPerfData[Index].PerfFreq := -50000;\n\nSleep(500);\n\nQueryPerformanceCounter(PerfData[Index].PerfEnd);\nQueryPerformanceFrequency(PerfData[Index].PerfFreq);\nPerfData[Index].TSCEnd := RDTSC();\n\n[I]\/\/ calculation MHz\nwith PerfData[Index] do\nbegin\nPerfDelta := PerfEnd - PerfStart;\nTSCDelta := TSCEnd - TSCStart;\nMhz := Trunc((TSCDelta * PerfFreq + 500000) \/ (PerfDelta * 1000000));\nend;\n\n[I]\/\/ if last 2 samplesmatches within a MHz done\nif Boolean(Index) then\nif (PerfData.Mhz = PerfData.Mhz) or\n(PerfData[Index].Mhz = PerfData[Index-1].Mhz + 1) or\n(PerfData[Index].Mhz = PerfData[Index-1].Mhz - 1) then break;\n\n[I]\/\/ advance to next sample\nInc(Index);\n\n[I]\/\/ if too many samples, then smth is wrong\nif Index >= MAX_ATTEMPTS then\nbegin\nAverage := 0;\nfor Index := 0 to MAX_ATTEMPTS do\nInc(Average, PerfData.Mhz);\n\n[I]\/\/ We got a warning below this line, but is not critical\nPerfData[Index - 1].Mhz := Trunc(Average \/ MAX_ATTEMPTS);\nbreak;\nend;\n\nend;\n\nWriteLn(' CPU Frequency: ' + IntToStr(PerfData[Index-1].Mhz) + ' MHz');\nReadLn;\nend.\n<\/div><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430: \u041a\u0430\u043a \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e Windows<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[433,1083],"tags":[603,1287,874,1646,1858,1877],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/818"}],"collection":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=818"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/818\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=818"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}