From: | Sami N��t�nen |
Date: | 10 Jan 2000 at 18:12:16 |
Subject: | Re: Strings and things |
On 08-Jan-00, amorel wrote.
> Statements and functions are slow? Then how is it that people on this very
> list advice when optimising to get a loop as small as possible and put
> everything in statement, functions and subroutines?
>
> Should I just add everything in the main loop?
>
well if you would really want to make fastest code you woudn't loop at all!
;)
But in general there are two kind of code optimizations size and speed
and these can not exist in same optimization after certain point.
So making copy of 10000 longwords would be fastest if no looping would have
used. (in reality it's just pure waiste of memory)
so instead of this:
lea addy1,a0
lea addy2,a1
move.w #10000,d0
loop: move.l (a0)+,(a1)+
subq.w d0
cmp.w #0,d0
bne loop
you can use this optimized:
lea addy1,a0
lea addy2,a1
move.w #9999,d0
loop: move.l (a0)+,(a1)+
dbra d0,loop
as you can see it's even sorter and much faster
BUT IF YOU USE THIS:
IT WILL BE A LOT FASTER. (will take about one tenth of the above code)
lea addy1,a0
lea addy2,a1
move.w #999,d0
loop: move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
dbra d0,loop
And the reason is very clear this optimization will remove 9000 TOTALLY
UNNECESSARY jump instructions! So real speed improve will almost allways
add the sizeof the required code.
But this kind of optimization will lead most people to false leads!
Because the most likely improvment comes from the used alcorythm.
After alcoryhtm is nearly perfect for the job you want it to do,
you should consider the need of codelevel optimizations.
So first use functions and find the best alcorythm, and after program is
working you can start to make those codelevel optimizations like inlining
those functions etc.
Sami N��t�nen
EMail: sami.naatanen@dlc.fi
---------------------------------------------------------------------
To unsubscribe, e-mail: blitz-list-unsubscribe@netsoc.ucd.ie
For additional commands, e-mail: blitz-list-help@netsoc.ucd.ie