More on Loops--Fusion and Unwinding

I wonder why it's not fusion and defusion...
Loop fusion should be a very common thing in PHP programming.
For example, 2 arrays;

for($i= 0;$i<30;++$i){
	$a[$i]++;
}
for($i = 0;$i<30;++$i){
	$b[$i]++;
}

FUSION!!!
for($i = 0l $i<30; ++$i){
	$a[$i]++;
	$b[$i]++;
}

On the other hand, loop unwinding is rarely seen in PHP.
Unwinding is to reduce the loop overhead by hand code the next few loop into the system.
For example
for($i=0;$i<101;++$i){
echo $i;
}

unwind
for($i=0;$i<101;$i+=4){
echo $i;
echo $i+1;
echo $i+2;
echo $i+3;
}

This technique is proven to have some speed gain, but, unwind is not all powerful, it comes with a cost.
For example, your code will be longer, and harder to read.
and, the unwinding require to have some previous knowledge about the loop. If the loop above is for 100 times instead of 101 times, the 2nd one will output 4 less items.
Even though it is possible to treat this by find the remain ones and use another loop to loop it though, but this make the code more complex than it should.

Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a Gravatar account, used to display your avatar. If you have a Gravatar account, used to display your avatar.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <fn>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.

More information about formatting options

What is 24 + 36?
To combat spam, please solve the math question above.
Honey Pot that kill bots