-1

I have a Java application which has 6 for loops. These loops do a massive computation, and the result is very slow. Sometimes, it seems like it is never going to end until you are 100 years old.

I ran Netbeans "profiler" to see which loop is taking more time. Unfortunately, I could not do that, because all the loops are in one single method and the profiler did not point loop by loop performance.

I really need to monitor the performance so I can address the performance issue of each loop individually. But how can I do this with Netbeans "profiler"?

Is there any alternative method that will help?

Tim B
  • 40,716
  • 16
  • 83
  • 128
PeakGen
  • 21,894
  • 86
  • 261
  • 463
  • 2
    "*because all the loops are in one single method *" => create methods! Also it sounds like your real problem is not so much what you do in the loop as the complexity of your algo - if these are 6 nested loops, that's what you need to solve... – assylias Apr 02 '14 at 09:09
  • @assylias: who said I got 6 nested loops. – PeakGen Apr 02 '14 at 09:56
  • Nobody - "it sounds like" => it's only a guess. My first comment still applies though. – assylias Apr 02 '14 at 09:57
  • @assylias: Right now we are trying on GPU programming. But `rootbeer` is buggy in windows 7. we can't reduce the complexity, we did to the max level. – PeakGen Apr 02 '14 at 10:02
  • Try [*this simple method*](http://stackoverflow.com/a/378024/23771). It will show you exactly where the time is being spent, at least in the Java code. – Mike Dunlavey Apr 02 '14 at 13:16

2 Answers2

1

Split your method into smaller methods and then use the profiling tools on those methods...

Tim B
  • 40,716
  • 16
  • 83
  • 128
0

For a simple analysis place some outputs like that:

for (/*for condition here*/) {
    final long startTime = System.currentTimeMillis();

    // your "massive computation" here


    final long duration = System.currentTimeMillis() - startTime;
    System.out.printf("%.2f sec\n", duration / 1000);
}

But, as Assylias mentioned, reorganizing your code (maybe using concurrency) might be your real task now.

Community
  • 1
  • 1
ifloop
  • 8,079
  • 2
  • 26
  • 35
  • That works, but often for this sort of thing you need more sophisticated average/worst case/etc timings. In other words count how many times you went through the loop, the total time all those took and the single longest time. – Tim B Apr 02 '14 at 12:51
  • Yes in deed! The method I posted above was only appointed to first-level analysis. Every further, more important analysis has to based on professional profiling. – ifloop Apr 02 '14 at 13:04