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.
Me and this article, sittnig in a tree, L-E-A-R-N-I-N-G!
That’s a smart way of loiokng at the world.
Could you write about Phiycss so I can pass Science class?
Play informative for me, Mr. internet wtrier.
Reiandg this makes my decisions easier than taking candy from a baby.