• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to measure performance speed of the method

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a class like this:




Then in another class where my main method is i have tried to use this


Now what i want to do is to measure the performance of my first method here. Is there any way to measure how fast my algorithm is?

The problem here is that my code is executed but i do not see in my console the time it takes. Am i doing it wrong?
 
author & internet detective
Posts: 41861
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From a design point of view, you should run the code in a loop and measure the average performance of a lot of runs. The reason is that Java optimizes so the first run isn't representative.

As far as not seeing anything on the console, try adding System.out.println("Before"); and System.out.println("After"); before and after. Do those get output? How are you running the code? Command line?
 
barlet south
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No i am using Eclipse. Could you please tell me how to put a for loop in that piece of code in order to get the average?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:From a design point of view, you should run the code in a loop and measure the average performance of a lot of runs. The reason is that Java optimizes so the first run isn't representative.



I would argue that a large number of the initial iterations should be simply ignored. This way, the just-in-time compiler can do its job, and you won't be measuring the JIT compiler. Also, while not a good idea for applications, it may be needed for benchmarks to force the GC. This way, you won't be measuring the garbage collector too.

Henry
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't it best to just use tools that specialize in benchmarking? I think most IDEs come with a profiler that can give you detailed information about performance.
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic