dpa97
dpa97

Reputation: 21

Calculate Java start up cost

I currently have a program in which I can print how long it takes to run the main method. When I run this program on command line and time it however, it takes considerably longer.

E.g.,

$ time java MyProgram "arg"
done by .004

real    0m0.105s
user    0m0.083s
sys     0m0.022s

My question is this- is it possible to calculate the start up cost of the java program within the program itself?

Upvotes: 2

Views: 155

Answers (1)

WalterM
WalterM

Reputation: 2706

You could put this as the first line in your main method. java.lang.management.ManagementFactory.getRuntimeMXBean().getUptime()

Upvotes: 2

Related Questions