0

I'm trying to compare on different levels two or more methods that are supposed to do the same thing. I'd like to compare them time-wise (who's faster), memory consuming-wise, etc.. but I don't want the results to be influenced by some background activity my computer may be doing (load an internet page, check for updates, etc...).

What are my options here to test my methods in an environment free of "distractions" that could influence the results.

Jean Henry
  • 436
  • 4
  • 14
  • As for memory consumption you'd just have to check the JVM's memory system, i.e. how much heap is being used etc. As for time usage, you could try to give everything but the JVM low priority, disconnect the computer from the network, stop all background processes etc. _But_ ... you just can't guarantee an exactly equivalent environment so you'd have to do multiple runs and take average timings and if the results are very close to each other they're probably equal. ... – Thomas Jul 18 '16 at 16:11
  • 1
    Note that jmh can also track memory consumption. – assylias Jul 18 '16 at 16:12
  • However, it might not be worth bothering with that so first think about the general attributes of your algorithms/methods: what would their big-O complexity be? How fast do you _need_ them to be and are they already fast enough? What would an optimization cost you and what would you gain from it? – Thomas Jul 18 '16 at 16:14

0 Answers0