I need the fastest routine



Hi,

I know this is the right place. I'm a just embarrassed to post such a silly question and code. If you could shed some light, I would appreciate very much!!!

In this project, I need to find the max and min integer from an array.
I came up with this code. It seems faster than the others I tried on.

---

procedure MinMaxArray( const aArray : Array of Integer; out aMax, aMin : integer );
var
MaxArray,
MinArray : array[boolean] of integer;
i : integer;
begin
aMax :=0;
aMin :=0;
i:=high( aArray );
if i>=0 then begin
MaxArray[True] := aArray[0];
MinArray[True] := aArray[0];
while i>0 do begin
MaxArray[ aArray[i] > MaxArray[True] ] := aArray[i];
MinArray[ aArray[i] < MinArray[True] ] := aArray[i];
dec(i);
end;
aMax := MaxArray[True];
aMin := MinArray[True];
end;
end;

---

Unfortunately it's not fast enough. I need more speed. I just wanted to be sure this routine is ok, or if there's some tricks to make it faster. If you guys think is a waste of time trying to improve on this routine, then I'll try to optimize other parts of the project.

I appreciate very much your help.

Clément



.



Relevant Pages

  • Re: Why do some many posters here detail the minutiae of their lives
    ... > My parents do the same thing. ... Who else goes through this routine every ... That would drive me nuts. ... I can't be bothered to waste that much time on ...
    (alt.support.diabetes)
  • GDI
    ... The routine works if I use the commented out code but I recently discovered a shorter way to do it. ... Only problem is the pie chart doesn't appear at all when I try the short method. ... 'Dim dg As Graphics ... ASCII a silly question, get a silly ANSI. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: The Promise of Forth
    ... and maybe find something better or possibly waste the ... thinking time. ... there is no reason that a language for doing routine things ...
    (comp.lang.forth)
  • Re: I need the fastest routine
    ... Clément Doss wrote: ... If you guys think is a waste of time trying to improve on this routine, then I'll try to optimize other parts of the project. ... This may sound dumb and I have not code this but why not do a quick sort and pick the first and last elements of the array? ...
    (borland.public.delphi.language.basm)