Please i need to call the main function of a java file several times like (100) times and measure the time it takes for it to complete. The objective is comparing the time with some other files. [literally speaking, I’m Implementing Algorithms].
I know that calculating the time can be achieved by:
long startTime = System.currentTimeMillis();
GetExecutionTimes ext=new GetExecutionTimes();
ext.callMethod();
long endTime = System.currentTimeMillis();
System.out.println("Total elapsed time in execution of method callMethod() is :"
+ (endTime-startTime));
*Where (“callMethod”) is the name of my method.
However, if i have a complete java file and i want to call its main function from another class (or file) while calculating its execution time, what’s the way to do that?
In Summary:
Task 1: Calling the main function of a java file several times from another class.
Task 2: Calculating the time it takes to execute (Task 1).
Please any suggestions or ideas for accomplishing tasks 1 and 2 are greatly appreciated.
Thanks in advance for your help,
Can you try with creating a JUnit test case and in the runner call your test’s method (which internally will call the actual object’s main). That way you might get the execution times via JUnit.