Sunday, March 11, 2012

Profile with jvisualvm

http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/

http://docs.oracle.com/javase/6/docs/technotes/tools/share/jvisualvm.html

Here is how to configure Eclipse IDE launcher
http://visualvm.java.net/eclipse-launcher.html


jvisualvm is part of JDK
[dave@dave ~]$ cd /app/jdk160_29/bin
[dave@dave bin]$ ls
appletviewer java jcontrol jstack policytool unpack200
apt javac jdb jstat rmic wsgen
ControlPanel javadoc jhat jstatd rmid wsimport
extcheck javah jinfo jvisualvm rmiregistry xjc
HtmlConverter javap jmap keytool schemagen
idlj java-rmi.cgi jps native2ascii serialver
jar javaws jrunscript orbd servertool
jarsigner jconsole jsadebugd pack200 tnameserv



Simple program comparing methods to create large string
package dave;

public class StringService {

int STRING_COUNT = 10000;

public String createString(String token) {

String out = "";

for (int i = 0; i < 1000; i++) {
out += token;
}

return out;

}

public String createStringWithStringBuffer(String token) {

StringBuffer out = new StringBuffer();

for (int i = 0; i < STRING_COUNT; i++) {
out.append(token);
}

return out.toString();
}

public String createStringWithStringBuilder(String token) {

StringBuilder out = new StringBuilder();

for (int i = 0; i < STRING_COUNT; i++) {
out.append(token);
}

return out.toString();

}

}




package dave;

public class TestProfiler {

public static void main(String[] args) {

String token = "dave";

StringService stringService = new StringService();

String result = null;

for (int i = 0; i < 10000; i++) {

result = stringService.createString(token);

result = stringService.createStringWithStringBuffer(token);

result = stringService.createStringWithStringBuilder(token);
}

}

}





Profiler with settings to select package


Sampler

No comments:

Post a Comment