Re: I need the fastest routine
- From: Stig Johansen <wopr.com@xxxxxxxxx>
- Date: Sat, 05 Jul 2008 07:20:09 +0200
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
.
- Follow-Ups:
- Re: I need the fastest routine
- From: Bob Gonder
- Re: I need the fastest routine
- From: Rudy Velthuis [TeamB]
- Re: I need the fastest routine
- From: Q Correll
- Re: I need the fastest routine
- References:
- I need the fastest routine
- From: Clément Doss
- Re: I need the fastest routine
- From: Q Correll
- Re: I need the fastest routine
- From: Clément Doss
- Re: I need the fastest routine
- From: Q Correll
- I need the fastest routine
- Prev by Date: Re: I need the fastest routine
- Next by Date: Re: FastMM.. any work in progress?
- Previous by thread: Re: I need the fastest routine
- Next by thread: Re: I need the fastest routine
- Index(es):
Relevant Pages
|