Re: I need the fastest routine



Q Correll wrote:

Clément,

| They are not fast enough :(
| And I have to scan the same array twice one to get the max and another
to get the min.

Try this:

procedure MinMaxArray( const aArray : Array of Integer; out aMax, aMin :
integer );
var i : integer;
begin
aMax := minInt;
aMin := maxInt;
for i := 0 to high(aArray) then
begin
aMax := max(aMax, aArray[i];
aMin := min(aMin, aArray[i];
end;
end;

Since this apperently is performance critical, he could also just use a
pointer, something like this:
procedure MinMaxArray( const aArray : Array of Integer; out aMax, aMin :
integer );
var i : integer;
var p : pinteger ;
begin
aMax := minInt;
aMin := maxInt;
p := @aArray[0] ;
for i := 0 to high(aArray) do
begin
if p^ > aMax then aMax := p^ ;
if p^ < aMin then aMin := p^;
inc(p);
end;
end;

Then he can avoid the overhead of function calls with the min and max
functions.

--
Best regards
Stig Johansen
.



Relevant Pages

  • Re: I need the fastest routine
    ... procedure MinMaxArray(const aArray: Array of Integer; out aMax, ... aMin: integer); ... var p: pinteger; ...
    (borland.public.delphi.language.basm)
  • Re: I need the fastest routine
    ... procedure MinMaxArray(const aArray: Array of Integer; out aMax, aMin: ... i, m, mmod, n: Integer; ...
    (borland.public.delphi.language.basm)
  • Re: I need the fastest routine
    ... procedure MinMaxArray(const aArray: Array of Integer; out aMax, aMin: integer); ...
    (borland.public.delphi.language.basm)
  • Re: Filter and compress an array
    ... && for the Array. ... you had written the following in your original post ... if Amin < A< Amax ...
    (comp.soft-sys.matlab)
  • Re: I need the fastest routine
    ... procedure MinMaxArray(const aArray: array of Integer; out aMax, aMin: ... and (LTempMin - LArrVal)); ...
    (borland.public.delphi.language.basm)