amitgangwar_vlsi
Member level 5
- Joined
- Jul 6, 2007
- Messages
- 88
- Helped
- 10
- Reputation
- 20
- Reaction score
- 2
- Trophy points
- 1,288
- Location
- Pune,India
- Activity points
- 1,913
laststep said:Can you provide some example, as far as i know if you replace for with the if statement then the if statement will be a long list and it is inefficient to do that. Imagine that you replace the for i = 0, i <=100, i++; , how long the if statement you need to write........
sp said:laststep said:Can you provide some example, as far as i know if you replace for with the if statement then the if statement will be a long list and it is inefficient to do that. Imagine that you replace the for i = 0, i <=100, i++; , how long the if statement you need to write........
hmm... you make me think a while
"for" statement is a loop statement and "if" statement is not.. "while" statement would be able to do the same as "for" statement
to use a case statement
its far better to build a case routine
if you have lots of checks of different idioms
so as to pass needed peramiters to the case and it returns the answer
one case rotuine for for all needed
mostly this is easy when dealing with variable ints
or even chars or a mix so... try to utilise one routine for all case switching
but a for loop uses less instruction cycles if you use it right
most people use for(t=0;t<=X;t++
this leaves an open buffer at zero returns to the rotuine {not zero t} -1t {null}
getting rid of the null can save many instructions from your processor etc
and also closes a potential back door
so write like
for (t=0;t<=x
{
switch(t)
{
case 0:...
...etc..
}
t++;
}
save one full cycle each read
perhaps this is where your code gives a bad performance
if you use a loop lots then this shows up as a loop run rize + 1 loop each run
or over 10 runtimes = 10% extra load the routine uses
each run
so switch case isnt better
infact most compilers also use a loop to do the switched case
so it uses far more instructions to process it
dont beleve the switchers stick to the loops
and optimise them like passing all variables to one loop including the adjustments
youll need to add to make the single loop perform any task
post your code ill optimise it
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?