Re: I need the fastest routine



Hi Rudy,

"Rudy Velthuis [TeamB]" <newsgroups@xxxxxxxxxxxx> schrieb im Newsbeitrag
news:xn0fsbtfwfpwjp100rnewsgroups@xxxxxxxxxxxxxxx
Rudy Velthuis [TeamB] wrote:
....
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.

(sorry, my english is not so good, i try it :)
i moved the access from parameters to local variables and .
A Test with three arrays (first has 50000 random-integers +/- 25000, next
has linear up 0,1,2,3,4,etc till 49999. and the last has linear down
0,-1,-2,-3 etc. till -49999) used per round averaged 10 cpu-clocks on
PIII-Cpu:

(*
procedure MinMaxArray(const aArray:array of integer; out aMax,
aMin:integer);
var // averaged 11 clocks per roundtrip
i:integer;
begin
aMax := aArray[Low(aArray)];
aMin := aMax;
for i := Low(aArray) + 1 to High(aArray) do
begin
if (aArray[i]<aMin) then aMin:=aArray[i];
if (aArray[i]>aMax) then aMax:=aArray[i];
end;
end;
*)

procedure MinMaxArray(const aArray:array of integer; out aMax,
aMin:integer);
var // averaged 10 clocks per roundtrip = 10% faster than above
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;

mfg.
Herby

--
http://www.hubert-seidel.de


.



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: ... if aArray> aMax then ... if aArray< aMin then ... FOUR pebbles. ...
    (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)