Re: I need the fastest routine



Hi all,

I really can't thank you enough for helping me with this one.

I have to come up with a short term solution. And replacing the minmax should come first. On a second step I will improve the overall design. For example:
While converting the doubles to integer, I can get the max and min. But I still must be sure that everything will work as expected. Once I understand better how this project works, I am sure I can get rid of that calls. In that part of the program, this routine is called 67%, followed by 58% of a matrix transformation routine.
I just can't imagine the performance boost if I replace the minmax routine with the one you provided.

I took the code you all posted and update Rudy's benchmark test.
Those are the results...


Array0 36484396 - 19 9999995
Array1 35067716 - 19 9999995
Array2 32072704 - 19 9999995
Array3 18110452 - 19 9999995
Array4 49961416 - 19 9999995
Array5 105275380 - 19 9999995 --> Original code
Array6 63633496 - 19 9999995

Does this means that if I replace my code with the one in Array4, there will be a 2x performance increase? Is that it?

Array3 is Hubert Seidel algorithm with a small change. I am working with local variables iMin and iMax instead of aMin and aMax. In my machine it worked fast. I guess I will have to bring this benchmark and run on the production machine to see which one is better suited for the processor :D


I can't thank you enough for helping. I just hope you all enjoyed this Saturday challenge! :D And if you keep lowering the cycles, I will most certainly test.

Clément.



Here is the code:

procedure MinMaxArray3(const aArray : Array of Integer; out aMax, aMin : integer );
var
i, m, mmod, n, iMax, iMin: Integer;
begin
aMax := 0;
aMin := 0;
if Length(aArray) > 0 then
begin
iMin := aArray[0];
iMax := aArray[0];
m := Length(aArray) div 4;
mmod := Length(aArray) mod 4;
n := 0;
for i := 0 to m -1 do
begin
if (aArray[n] < iMin) or (aArray[n+1] < iMin) or
(aArray[n+2] < iMin) or (aArray[n+3] < iMin) then
begin
if aArray[n] < iMin then
iMin := aArray[n];
if aArray[n+1] < iMin then
iMin := aArray[n+1];
if aArray[n+2] < iMin then
iMin := aArray[n+2];
if aArray[n+3] < iMin then
iMin := aArray[n+3];
end;

if (aArray[n] > iMax) or (aArray[n+1] > iMax) or
(aArray[n+2] > iMax) or (aArray[n+3] > iMax) then
begin
if aArray[n] > iMax then
iMax := aArray[n];
if aArray[n+1] > iMax then
iMax := aArray[n+1];
if aArray[n+2] > iMax then
iMax := aArray[n+2];
if aArray[n+3] > iMax then
iMax := aArray[n+3];
end;

Inc(n, 4);
end;

for i := 0 to mmod-1 do
begin
if aArray[i+n] < iMin then
iMin := aArray[i+n];
if aArray[i+n] > iMax then
iMax := aArray[i+n];
end;
aMax := iMax;
aMin := iMin;
end;
end;

.



Relevant Pages

  • Re: Zähler begrenzen
    ... Function MinMax ... If iNum < iMin Then ... ElsIf iNum> iMax Then ...
    (microsoft.public.de.inetserver.iis.asp)
  • Re: I need the fastest routine
    ... I have changed it to 1 offset instead of 0 offset. ... Using pointers ... IF PIa^> iMax THEN ... IF PIa^< iMin THEN ...
    (borland.public.delphi.language.basm)
  • Re: I need the fastest routine
    ... but current processors minimize the jump in the loop so much ... PIa^> iMax) then BEGIN ... PIa^< iMin) then BEGIN ... Then i tried 'unrolling' with an array of 8, ...
    (borland.public.delphi.language.basm)
  • Re: Generalized range
    ... I think just increasing a "counter" from iMin to iMax should be fine, achieving more precision by making computations fuzzy -- i don't know, perhaps it's very good. ... elsewhere) is the addition/subtraction of a fixed epsilon to ensure ...
    (comp.lang.python)
  • Generalized range
    ... return range(iMin, iMax, iStep) ... elsewhere) is the addition/subtraction of a fixed epsilon to ensure ... particular values of iMax, iMin and iStep. ...
    (comp.lang.python)