Cpu Speed




UNIT  UCPUSPD;
INTERFACE
USES
    WINDOWS,  MESSAGES,  SYSUTILS,  CLASSES,  GRAPHICS,  CONTROLS,  FORMS,  DIALOGS,
    COMCTRLS,  STDCTRLS,  BUTTONS;
TYPE
    TFORMCPUSPEED  =  CLASS(TFORM)
        BITBTNSTART:  TBITBTN;
        BITBTNSTOP:  TBITBTN;
        LABELCPUSPEED:  TLABEL;
        PROCEDURE  BITBTNSTARTCLICK(SENDER:  TOBJECT);
        PROCEDURE  BITBTNSTOPCLICK(SENDER:  TOBJECT);
    PRIVATE
        {  PRIVATE  DECLARATIONS  }
        STOP:  BOOLEAN;
    PUBLIC
        {  PUBLIC  DECLARATIONS  }
    END;
VAR






UNIT  UCPUSPD;
INTERFACE
USES
    WINDOWS,  MESSAGES,  SYSUTILS,  CLASSES,  GRAPHICS,  CONTROLS,  FORMS,  DIALOGS,
    COMCTRLS,  STDCTRLS,  BUTTONS;
TYPE
    TFORMCPUSPEED  =  CLASS(TFORM)
        BITBTNSTART:  TBITBTN;
        BITBTNSTOP:  TBITBTN;
        LABELCPUSPEED:  TLABEL;
        PROCEDURE  BITBTNSTARTCLICK(SENDER:  TOBJECT);
        PROCEDURE  BITBTNSTOPCLICK(SENDER:  TOBJECT);
    PRIVATE
        {  PRIVATE  DECLARATIONS  }
        STOP:  BOOLEAN;
    PUBLIC
        {  PUBLIC  DECLARATIONS  }
    END;
VAR



    FORMCPUSPEED:  TFORMCPUSPEED;
IMPLEMENTATION
{$R  *.DFM}
FUNCTION  GETCPUSPEED:  DOUBLE;
CONST
    DELAYTIME  =  500;  //  MEASURE  TIME  IN  MS



VAR
    TIMERHI,  TIMERLO:  DWORD;
    PRIORITYCLASS,  PRIORITY:  INTEGER;
BEGIN
    PRIORITYCLASS  :=  GETPRIORITYCLASS(GETCURRENTPROCESS);
    PRIORITY  :=  GETTHREADPRIORITY(GETCURRENTTHREAD);
    SETPRIORITYCLASS(GETCURRENTPROCESS,  REALTIME_PRIORITY_CLASS);
    SETTHREADPRIORITY(GETCURRENTTHREAD,  THREAD_PRIORITY_TIME_CRITICAL);
    SLEEP(10);
    ASM
        DW  310FH  //  RDTSC
        MOV  TIMERLO,  EAX
        MOV  TIMERHI,  EDX
    END;
    SLEEP(DELAYTIME);
    ASM
        DW  310FH  //  RDTSC
        SUB  EAX,  TIMERLO
        SBB  EDX,  TIMERHI
        MOV  TIMERLO,  EAX
        MOV  TIMERHI,  EDX
    END;
    SETTHREADPRIORITY(GETCURRENTTHREAD,  PRIORITY);
    SETPRIORITYCLASS(GETCURRENTPROCESS,  PRIORITYCLASS);
    RESULT  :=  TIMERLO  /  (1000.0  *  DELAYTIME);
END;
PROCEDURE  TFORMCPUSPEED.BITBTNSTARTCLICK(SENDER:  TOBJECT);
BEGIN
    BITBTNSTART.ENABLED  :=  FALSE;
    BITBTNSTOP.ENABLED  :=  TRUE;
    STOP  :=  FALSE;
    WHILE  NOT  STOP  DO
    BEGIN
        LABELCPUSPEED.CAPTION  :=  FORMAT('CPU  SPEED:  %F  MHZ',  [GETCPUSPEED]);
        APPLICATION.PROCESSMESSAGES;
    END;
    BITBTNSTART.ENABLED  :=  TRUE;
    BITBTNSTOP.ENABLED  :=  FALSE;
END;
PROCEDURE  TFORMCPUSPEED.BITBTNSTOPCLICK(SENDER:  TOBJECT);
BEGIN
    STOP  :=  TRUE;
END;
END.



Vote This Post DownVote This Post Up (+2 votes)
Loading...



این نوشته در Delphi ارسال شده است. افزودن پیوند یکتا به علاقه‌مندی‌ها.

5 Responses to Cpu Speed

  1. Ceylin می‌گوید:

    Me and this article, sittnig in a tree, L-E-A-R-N-I-N-G!

  2. Ayumi می‌گوید:

    Could you write about Phiycss so I can pass Science class?

  3. Sebastian می‌گوید:

    Play informative for me, Mr. internet wtrier.

  4. Giullia می‌گوید:

    Reiandg this makes my decisions easier than taking candy from a baby.

پاسخ دهید