Hi Jon, You function returns the best time.
Still I wonder if I should make and average of all times or to look only for the smallest time. I think I should look for the smallest time. Jon P. Grewer wrote: > Using Wilfried's asm code and Rob's tight Delphi code as inspiration and > jumping off point: This is my first ASM routine ever. > > function Max3(a, b, c: integer): integer; > // eax : first param & Result > // ecx : second param > // edx : third param > asm > cmp eax, ecx > jl @less // ecx > eax > cmp eax, edx > jl @less2 // eax > ecx but less than edx. edx is max. 2 > compares, 1, assignment, 1 jump > ret // eax is max. 2 compares, 0 assignments, 0 jumps > > @less: // ecx > eax.. Is ecx greater than edx? > cmp ecx, edx > jl @less2 // edx is max. 2 compares, 1 assignment, 2 jumps > mov eax, ecx // ecx is max. 2 compares, 1 assignment, 1 jump > ret > > @less2: > mov eax, edx // edx is max > end; > > Warmest regards and thanks for the inspiration, > -- Jon Grewer > > >> Message: 1 >> Date: Sat, 25 Aug 2007 23:06:56 +0200 >> From: CubicDesign <[EMAIL PROTECTED]> >> Subject: Re: maximum of 3 numbers >> To: Borland's Delphi Discussion List <[email protected]> >> Message-ID: <[EMAIL PROTECTED]> >> Content-Type: text/plain; charset=ISO-8859-1; format=flowed >> >> >> >> Rob Kennedy wrote: >> >> >>> The name of that unit suggests it's a unit written for the Intel 80387 >>> math coprocessor; is it really that old? >>> >>> >>> >> I don't know. There was no source code, only a DCU. But it is for Delphi. >> I have found also a library (with the same name) which is for Pascal :) >> >> >>> Being written in assembler and performing the same as the function in the >>> Math unit aren't mutually exclusive things. >>> >>> >>> >> The DCU was offered as a faster replacement for Borland functions. It >> didn't performed much better. >> Indeed this doesn't mean that the code was not written in ASM. Anyway I >> never said that it wasn't made in ASM. I just said that the speed of >> that DCU was similar with Borland's. >> Usually ones expect at least a 2x speed improvement from an ASM code >> (also a 5x speed improvement is not exaggerated). >> >> >>> For one hundred million things, that seems pretty fast already. How fast >>> do you want it go instead? >>> >>> >>> >> The speed of my code (2 sec) is ok but there are also other pieces of >> code in that loop, so the total time for the whole the loop can go up to >> 10-30 seconds. >> Anyway I got a piece of code in ASM from Wilfried (thanks again >> Wilfried) which is about 2-3 times faster than my plain Delphi code. >> Yesterday I spend the whole day optimizing that loop and I decreased the >> time with about 50-55%. >> Is still unacceptable since I have lot of data to process. >> >> I have only minor understanding of ASM (enough to understand ASM code >> but not enough to write) so I am thinking seriously in learning more ASM. >> >> >> >> >>> That executes two comparisons and a maximum of three assignments. >>> >>> function Max(const A, B, C: Integer): Integer; >>> begin >>> if A > B then >>> if A > C then >>> Result := A >>> else >>> Result := C >>> else >>> if B > C then >>> Result := B >>> else >>> Result := C; >>> end; >>> >>> That executes two comparisons and a maximum of one assignment. >>> >>> >>> >>> >> Great! Sure it will execute faster than mine. Indeed it will execute >> comparisons to get the final result. >> Thank you very much. >> >> It is funny how a piece of code can get faster by using more lines of >> code :) >> >> >> > > _______________________________________________ > Delphi mailing list -> [email protected] > http://www.elists.org/mailman/listinfo/delphi > > _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

