0

I need to compare the run time of 2 programs. I capture the elapsed time of each program using System.nanoTime(). One program returns with a time of 1449870040074994000 nano seconds, the other with a time of 1449870040080970000 nano seconds.

I am using double percent = ((big-small)/big)*100; but this is returning 0.0. Is this because double can't represent such a small number?

What am I doing wrong and how can I calculate this correctly?

Note that I need to make a conclusion along the lines of "Program A is on average x% faster than Program B"

Thanks!

  • 1
    Try `double percent = (big - small) * 100.0 / big;` as `double` can represent such a small number however `long` cannot represent any value between 0 and 1. – Peter Lawrey Dec 11 '15 at 22:26
  • Also, to get uptime of program `ManagementFactory.getRuntimeMXBean().getUptime()` – WalterM Dec 11 '15 at 22:34

0 Answers0