Re: I need the fastest routine
- From: Clément Doss <cdoss@xxxxxxxxxx>
- Date: Sat, 05 Jul 2008 20:03:09 -0300
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;
.
- Follow-Ups:
- Re: I need the fastest routine
- From: Rudy Velthuis [TeamB]
- Re: I need the fastest routine
- From: Stig Johansen
- 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
- I need the fastest routine
- Prev by Date: Re: I need the fastest routine
- Next by Date: Re: I need the fastest routine
- Previous by thread: Re: I need the fastest routine
- Next by thread: Re: I need the fastest routine
- Index(es):
Relevant Pages
|