Results 1 to 14 of 14
- 05-28-2008, 03:39 AM #1
Member
- Join Date
- May 2008
- Posts
- 1
- Rep Power
- 0
- 05-28-2008, 04:17 AM #2
depends on compiler but you probably won't notice any difference in speed even if you run it a trillion times.
My IP address is 127.0.0.1
- 05-28-2008, 04:27 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
In most of the cases, each line of a code effect to the execution completion time. If you can remove at least one line of code, it's much better.
- 05-28-2008, 04:31 AM #4
This true in only some case Eranga. Think of inlining your methods although this adds more code it also makes your program faster because of the lack of method calls. Another example would be to hardcode in a inner loop for an array search.
My IP address is 127.0.0.1
- 05-28-2008, 04:47 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes, I mentioned on my replay pal. Please read what I have written there carefully before comments on it.
And you know what, array search is much faster than calling a method. If you not believe me do a simple JUnit test and see.
- 05-28-2008, 04:53 AM #6
I'm confused by what you mean. Arrays were never mentioned in this thread nor where method calls
My IP address is 127.0.0.1
- 05-28-2008, 04:58 AM #7
I do agree that the execution time between them is negligible, but it is just good practice to use the not statement. You don't want to have an empty block. It may have to go into the block and then see that it is empty which would take time, but compilers should optimize around that.
I would think that it would be faster to use a try/catch block on the rs.close, then it wouldnt have to do anything extra unless the file was null which i am assuming isnt going to happen very often.
- 05-28-2008, 05:03 AM #8
Most compilers will optimsize your if statment. Mostly what you want to consider is readability.
My IP address is 127.0.0.1
- 05-28-2008, 05:43 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 05-28-2008, 11:49 AM #10
You may code it in favor to what you are expecting....Please suggest me the best practice of using if loop with 'NOT' condition.
For example:
if (rs != null){rs.close();}
if (rs == null){} else{rs.close();}
Which of the above is optimised?
The first one may be faster than the second one, only if that portion always executes successfully and should be close,
What if rs has 51% chance to be null? therefore the second one is faster than the first one....Last edited by sukatoa; 05-28-2008 at 11:52 AM.
freedom exists in the world of ideas
- 05-28-2008, 01:43 PM #11
I do believe but I could be wrong that with a smart compiler it would take the exact amount of time either way.
My IP address is 127.0.0.1
- 05-28-2008, 02:14 PM #12
I agree. I would expect the java compiler to be smart enough to get those both compiled well. This would be different with an interpreted language.
- 05-28-2008, 09:32 PM #13
Member
- Join Date
- May 2008
- Posts
- 21
- Rep Power
- 0
it is best to avoid "NOT" other then "NOT EQUALS" as it will take an extra conversion to convert the result to its not
and more over try to inscribe less executed code int the loop if u are going for multiple condition and using && in between vice-versaget new coding problems at CODERWORDS
- 05-29-2008, 12:11 PM #14
Member
- Join Date
- May 2008
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
I need help on a practice code for java
By Sageinquisitor in forum New To JavaReplies: 12Last Post: 07-13-2010, 04:00 PM -
How to use Do While loop
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:45 PM -
How to use While loop
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:44 PM -
Building small web application in java for practice.
By Saurabh321 in forum New To JavaReplies: 1Last Post: 02-01-2008, 03:38 PM -
Web Services - IBM Expands SOA Management Practice
By Felissa in forum Web FrameworksReplies: 0Last Post: 06-25-2007, 04:08 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks