This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Determining program memory and speed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Determining program memory and speed " Watch "Determining program memory and speed " New topic
Author

Determining program memory and speed

justin smythhe
Ranch Hand

Joined: Jul 06, 2012
Posts: 107
How can I determine the exact (well almost) memory used by a program at a particular instant ? How can I also estimate its speed ?
Are there any case studies or examples which show how trade-offs have been made between memory and speed ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39088
    
  23
That sort of thing is your lowest priority. There are all sorts of profiling tools available, including one called virtualVM or similar which comes ready‑made with Java6+.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1509
    
    5

As Campbell has suggested, in built tools are much easy to use and quite reliable. One utility is jvisualvm.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39088
    
  23
Anayonkar Shivalkar wrote:. . . One utility is jvisualvm.
That is probably what I meant. Sorry for getting the name wrong.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1509
    
    5

Campbell Ritchie wrote:
Anayonkar Shivalkar wrote:. . . One utility is jvisualvm.
That is probably what I meant. Sorry for getting the name wrong.


Yes, we are talking about same utility - jvisualvm comes in-built with JDK(6+).
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

For more detail about java visual VM => visualvm tutorial
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

justin smythhe wrote:How can I also estimate its speed ?

If you mean the execution time of a specific method or program - very carefully. It's easy to make false assumptions about speed unless your testing harness is very comprehensive. At the very least you need to test multiple iterations over time and under stress and look at averages, rather than relying on single executions; but that's only scratching the surface.

Are there any case studies or examples which show how trade-offs have been made between memory and speed ?

Possibly, but you'd have to find one targeted for your specific application; and like Campbell, I'd say that this should be a very low priority. You're likely to save far more time by doing basic things like avoiding file I/O than you will by micro-optimizing. And how much is a Gb of memory these days: $50? That's about 2 hours of a junior programmer's time.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
GeeCON Prague 2014
 
subject: Determining program memory and speed