Fastest Min/Max of Int Array Routine

Use this function to get the Max and Min value from series of data within integer array...
procedure MinMaxArray(const aArray:array of integer; out aMax,aMin:integer);
var
i,mi,ma:integer;
begin
ma := aArray[Low(aArray)];
mi := ma;
for i := Low(aArray) + 1 to High(aArray) do
begin
if (aArray[i] < mi) then mi:=aArray[i];
if (aArray[i] > ma) then ma:=aArray[i];
end;
aMax := ma;
aMin := mi;
end;

If you need more speed, a BASM version could be used as follow...

2 comments:

pichkari said...
This comment has been removed by the author.
pichkari said...

instead of using two if loops .. you can do it better by using elseif instead of second if