Re: I need the fastest routine



Rudy Velthuis [TeamB] wrote:

begin
if p^ > aMax then aMax := p^ ;
if p^ < aMin then aMin := p^;
inc(p);
end;

begin
if aArray[I] > aMax then
aMax := aArray[I];
if aArray[I] < aMin then
aMin := aArray[I];
end;

begin
Value := aArray[I];
if Value > aMax then
aMax := Value;
if Value < aMin then
aMin := Value;
end;
end;

I just coded all three versions in one program. Your code and my first
code produce exactly the same machine code. Not one single instruction
is different.

My second variety is a little simpler, but is not measurably faster or
slower.

--
Rudy Velthuis [TeamB] http://www.teamb.com

Fundamentalists: believe 2+2=5 because It Is Written. Somewhere.
They have a lot of trouble on their tax returns.

"Moderate" believers: live their lives on the basis that 2+2=4.
But go regularly to church to be told that 2+2 once made 5, or
will one day make 5, or in a very real and spiritual sense,
should make 5.

"Moderate" atheists: know that 2+2=4 but think it impolite to say
so too loudly as people who think 2+2=5 might be offended.

"Militant" atheists: "Oh for pity's sake. HERE. Two pebbles. Two
more pebbles. FOUR pebbles. What is WRONG with you people?"
.



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: Anyone recognise this sort algorithm?
    ... if A> AMax then AMax = A ... if A< Amin then Amin = A ... Counting sort runs in O, if the range is a known constant. ... Well spotted Arthur, I was convinced this type of sort had been ...
    (comp.programming)
  • Re: Anyone recognise this sort algorithm?
    ... I dont have the dos bat code to hand but here is what I mean by no ... if A> AMax then AMax = A ... if A< Amin then Amin = A ... @echo off ...
    (comp.programming)
  • Re: I need the fastest routine
    ... Rudy Velthuis [TeamB] wrote: ... Your thought being that Value would be in the local stack? ... Note that aMin and aMax are out variables, ...
    (borland.public.delphi.language.basm)
  • Re: Anyone recognise this sort algorithm?
    ... sub crapsort ... Amin = A ... if A> AMax then AMax = A ... I agree that it looks like a really bad select sort. ...
    (comp.programming)