Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Efficiency of Each Java Operation

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know of a good resource/s that could tell me the efficiency of individual operation in Java


I don't know whether to put a try-catch block in a loop or vice versa....



It would help to have a list of operations and their resource overhead.



Since I'm such a beginner I might just get this thing to work albeit inefficiently so I can get the thing in on time. ..but it bothers me.


-J
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be worrying about making your code clear and readable. Efficiency, especially down to the individual operation level, is not something you should be thinking of.
 
Jai Gates
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thanks.
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jai Gates wrote:I don't know whether to put a try-catch block in a loop or vice versa....


You choose the one that makes the most sense.

It would help to have a list of operations and their resource overhead.


Nope. Not something that should be a factor in deciding how to write your code.

Learn good and efficient algorithms as you go along, yes. But worrying about the efficiency of individual operations, or worse, writing contorted code because you think it will be "more efficient", will definitely steer you wrong.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jai Gates wrote:Does anyone know of a good resource/s that could tell me the efficiency of individual operation in Java



No, and you don't need it. The "efficiency" at the very low level is something you can't control and that will be handled differently by different JVM implementations and versions. If you want your program to run efficiently, use good design and appropriate algorithms and data structures.

I don't know whether to put a try-catch block in a loop or vice versa....



You won't make that choice for "efficiency" reasons. You'll make it for design and functionality reasons. If you want your entire loop to stop when one exception occurs, put the loop inside the try. If you want to be able to recover from an exception on a given iteration and continue looping, put the try inside the loop.

Write code that says what you mean. Don't try to be "clever" in the name of "efficiency."

Since I'm such a beginner I might just get this thing to work albeit inefficiently so I can get the thing in on time. ..but it bothers me.



Good performance will come from things like using Sets to find an intersection of collections, rather than an O(N^2) nested for loop over two Lists. You won't see a difference from things like the relative location of your loops and try statements. For good performance, write dumb code!

 
Jai Gates
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

For good performance, write dumb code!




Advice I can follow xD thanks for article. will read.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jai Gates wrote:Advice I can follow xD thanks for article. will read.


And, just in case you're still tempted, my favourite quotation about optimization:

W.A. Wulf wrote:"More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason — including blind stupidity."



Winston
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic