- Joined
- May 23, 2008
- Messages
- 1,785
- Reaction score
- 0
- Points
- 36
Hi everyone!
I have a quick programming question concerning the optimization of some code. I'm working in Java, I have the following loop (in pseudo-code):
p=1;
for(i=A to B) {
p = p*i;
}
I know what A and B are, and I'm looking to compute "p". Normally I'd just run the loop and be done with it, but the method this loop is in gets called over 1 million times in a typical run of the program. Needless to say, if A and B are far enough apart, it takes a while to run.
What I'd like to be able to do is eliminate the loop I have up there and replace it with a single expression, thus speeding up the calculations. Anyone know if what I'm after is possible?
I have a quick programming question concerning the optimization of some code. I'm working in Java, I have the following loop (in pseudo-code):
p=1;
for(i=A to B) {
p = p*i;
}
I know what A and B are, and I'm looking to compute "p". Normally I'd just run the loop and be done with it, but the method this loop is in gets called over 1 million times in a typical run of the program. Needless to say, if A and B are far enough apart, it takes a while to run.
What I'd like to be able to do is eliminate the loop I have up there and replace it with a single expression, thus speeding up the calculations. Anyone know if what I'm after is possible?