C
Chad
I was looking through some old comp.lang.c posts and came across the
following comment made by Chris Torek
"This is a typical optimization in any compiled, imperative language.
The theory is that loops -- especially inner loops, when loops are
nested -- contain code that will be run quite a bit, so if there is
some way to move some computation outside the loop and run it just
once, instead of every time, that should help a lot. Another
technique is "strength reduction", in which a "strong" operation
(like a multiplication) is "reduced" to an equivalent "weaker" one
(such as repeated addition) that should go faster:
for i in [0..N1) do
for j in [0..N2) do
op(arr[i;j])
The subscript operation here may (depending on the language) involve
multiplication, but the result will be the sequence {0,4,8,12,16,...}
or some such."
The following comment is from the following url
http://groups.google.com/group/comp...-8&q=evaluation+vs+execution#76fa5a51b83cb3f1
How does he get the sequence {0,4,8,12,16,...} from the for loops?
Chad
following comment made by Chris Torek
"This is a typical optimization in any compiled, imperative language.
The theory is that loops -- especially inner loops, when loops are
nested -- contain code that will be run quite a bit, so if there is
some way to move some computation outside the loop and run it just
once, instead of every time, that should help a lot. Another
technique is "strength reduction", in which a "strong" operation
(like a multiplication) is "reduced" to an equivalent "weaker" one
(such as repeated addition) that should go faster:
for i in [0..N1) do
for j in [0..N2) do
op(arr[i;j])
The subscript operation here may (depending on the language) involve
multiplication, but the result will be the sequence {0,4,8,12,16,...}
or some such."
The following comment is from the following url
http://groups.google.com/group/comp...-8&q=evaluation+vs+execution#76fa5a51b83cb3f1
How does he get the sequence {0,4,8,12,16,...} from the for loops?
Chad