var
wert,a,b,c,x,y,z,ergebnis,x2,y2,z2,ergebnis2,x3,y3,z3,ergebnis3:integer;
FUNCTION TimeStamp:int64;
asm
rdtsc
end;
PROCEDURE Test1;
begin
Ergebnis := (A*x + B*Y + C*Z)
div Wert;
Ergebnis2 := (A*x2 + B*Y2 + C*Z2)
div Wert;
Ergebnis3 := (A*x3 + B*Y3 + C*Z3)
div Wert;
end;
PROCEDURE Test2;
asm
fild wert
fild a
fild b
fild c
fild x
fmul st,st(3)
fild y
fmul st,st(3)
faddp
fild z
fmul st,st(2)
faddp
fdiv st,st(4)
fistp ergebnis
fild x2
fmul st,st(3)
fild y2
fmul st,st(3)
faddp
fild z2
fmul st,st(2)
faddp
fdiv st,st(4)
fistp ergebnis2
fild x3
fmulp st(3),st
fild y3
fmulp st(2),st
fild z3
fmulp
faddp
faddp
fdivrp
fistp ergebnis3
end;
PROCEDURE TestPerformance;
const count=100;
var priorityclass,priority:integer; samask,pamask,tamask:cardinal;
t0,t1,t2,tts:Int64; i:integer;
begin
GetProcessAffinityMask(GetCurrentProcess,pamask,samask);
if pamask=0
then exit;
tamask:=1;
while tamask
and pamask=0
do tamask:=tamask
shl 1;
SetThreadAffinityMask(GetCurrentThread,tamask);
priorityclass:=GetPriorityClass(GetCurrentProcess);
priority:=GetThreadPriority(GetCurrentThread);
SetPriorityClass(GetCurrentProcess,REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread,THREAD_PRIORITY_TIME_CRITICAL);
// Etwas einheizen
for i:=1
to 100000000
do;
// Feststellen wieviel Ticks TimeStamp braucht
tts:=High(int64);
for i:=1
to count
do begin
t0:=TimeStamp;
t0:=TimeStamp-t0;
if t0<tts
then tts:=t0;
end;
// Ticks für Routine 1
t1:=High(int64);
for i:=1
to count
do begin
t0:=TimeStamp;
Test1;
t0:=TimeStamp-t0;
if t0<t1
then t1:=t0;
end;
dec(t1,tts);
// Zeit für TimeStamp abziehen
// Ticks für Routine 2
t2:=High(int64);
for i:=1
to count
do begin
t0:=TimeStamp;
Test2;
t0:=TimeStamp-t0;
if t0<t2
then t2:=t0;
end;
dec(t2,tts);
// Zeit für TimeStamp abziehen
SetThreadPriority(GetCurrentThread,priority);
SetPriorityClass(GetCurrentProcess,priorityclass);
SetThreadAffinityMask(GetCurrentThread,pamask);
ShowMessage(IntToStr(t1)+'
'+IntToStr(t2)+'
'+IntToStr(t1-t2));
end;
PROCEDURE TMain.Test;
begin
a:=12345;
b:=23456;
c:=34567;
x:=12;
y:=13;
z:=14;
x2:=123;
y2:=123;
z2:=125;
x3:=234;
y3:=235;
z3:=236;
wert:=37;
testperformance;
end;