Re: I need the fastest routine



Hello Herby,

I see Double instead of Integer!
What is the history?

I am hired to improve the diagnostic routines of a machine that tests hardware device. The hardware send "arrays" of doubles that must be checked according to their index. That's why I can't order the array. For example, if the Min Max values are in places 11 and 18, then a specific routine must be called.
They had to deal with some internal issues because a larger volume of devices were diagnosed as defective, but in fact were Ok. The former software were taking longer then 5 or 6 minutes to diagnose the component, and this timeout generated a defective flag.
I had little time to digest the routines, and to find IF something were wrong.
The code is very confusing. And I couldn't ask for help from the former developer.
So I decided to make the less possible change to "prove" myself I was right.

When I saw this code :

procedure MinMaxArrayOrig( aArray : Array of Double; out aMinArray,
aMaxArray : Array of double );
var
i : integer;
begin
aMinArray[1]:=aArray[0];
aMaxArray[1]:=aArray[0];
i:=1;
while (i<=high(aArray)) do begin
aMaxArray[ ord( aArray[i] > aMaxArray[1] ) ] := aArray[i];
aMinArray[ ord( aArray[i] < aMinArray[1] ) ] := aArray[i];
inc(i)
end;
end;

I played around with it until I had the idea to change it from Array of Double to Array of Integer. In some of the simpler diagnostic routines, the changes were fairly easy. A simple conversion from Array of Double to Array of Integer and removing MinArray and MaxArray gave me boost I needed. Once I wrote the version with integer and the manager saw the improvements and decided to put some "know" device results as control group.
All tested as expected. Which gave me some extra-time. So I posted my "Original" code here.
With the routines the community wrote. Needless to say that the improvements where even bigger. Which made them think about re-planning their diagnostics routines.

And that's what I'm doing :-)

From a basic component spec I can tell you that the array are not "continuous". I'll try to explain with an example, I place integer just to simplify. The real numbers are doubles:
The device don't return an array like 1 2 3 4 5 6 7 8 9 10.... 5000
but some numbers from 1000..3000, 5000..6000, 6500..6800
In the above example 3001..4999 does not exists, as doesn't 6001..6499.
The larger array I worked with had 5000 elements. But the other said they saw larger.

Anyway thanks for posting your code here. I never would imagine that the routine could be improved that much!!!
The improvement went from almost 5 min (Array of doubles) to 3.5 min (Original post Array of integer) to less then 2 (using the routines posted in this newsgroup).


Very enlightening!
Clément
.



Relevant Pages

  • array argument checking style issue
    ... developing a library of routines. ... and the array arguments will be assumed shape arrays. ... My library contains subroutine foo, ... Can I choose a debugging option that ...
    (comp.lang.fortran)
  • Re: sorting roman numbers
    ... Ivo wrote: ... I've worked with roman numerals... ... VIIII is more appropriate for 9, but my routines stick with IX), at ... (You can try adding them into the $lookup array -- notice how the ...
    (comp.lang.php)
  • Re: Replace Better
    ... longer (expand byte array) or shorter routines. ... span something like a "virtual array" over an already ... always work with normally passed VB-String-Parameters ...
    (microsoft.public.vb.general.discussion)
  • Re: exploring a fortran(?) library
    ... I will write some fortran or C routines for use with matlab; I need the MAX efficiency in array management, because of intensive matrix multiplication and factorization. ...
    (comp.lang.fortran)
  • PowerMean
    ... Demonstrate various ways of summarising/averaging a list of doubles ... @param numbers array of doubles ... double sum = 0; ...
    (comp.lang.java.help)