Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Do a self benchmarking for my code [duplicate]

zyan Billings:

This question already has an answer here:

  • How do I write a correct micro-benchmark in Java? 11 answers

I am looking for an smart way that i can benchmark my program to make sure that my newly written Code is better than old one. What is the best to get run-time and garbage collection info etc? My piece of code as below. Please help me to make it better.

public static void main(String... args) {
long start = System.currentTimeMillis();
//my code
long end = System.currentTimeMillis();
System.out.println(Long.toString(end - start));

public static String printGCStats() {
long totalGarbageCollections = 0;
for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
long count = gc.getCollectionCount();
if (count >= 0) {
totalGarbageCollections += count;
return "Garbage Collections: " + totalGarbageCollections;

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Do a self benchmarking for my code [duplicate]


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription