I have written a java program that can compile, execute others submitted code(cpp, java). I am doing this using java's process class. Process class invoke the g++
or java compiler
. For some purpose I need to know what is the actual execution time of that process or how many time that code takes to execute.
process.waitFor(2000, TimeUnit.MILLISECONDS)
This process is waiting for 2000 milisecond but If the process done in less than 2000 milisecond how can I know what is the time that process takes?
======Update===== I currently doing this like a old way.
StopWatch.Start();
process.waitFor(dto.getTimeLimit(), TimeUnit.MILLISECONDS)
long timeEplased = StopWatch.Stop();
StopWatch
is my written class that calculate the elapsed time using System.nanoTime()
.