Reputation: 1397
I have a java class file in my hand and can simply able to run it from windows cmd to view the output. Only thing I need to observe the running time of this java program depending on different input parameters. I don't have the source code so I can not modify it to generate the running time for me. Please suggest possible way out to observe this. Thanks in advance.
Upvotes: 0
Views: 768
Reputation: 25950
You can write a simple Java program to observe this. Use runtime executions within your new code and observe the execution time.
A sample overview of this new code:
//... before your class runs.
Runtime.getRuntime().exec("java -jar yourClass");
//... after your class runs.
Upvotes: 0
Reputation: 7899
What you can do is you can write a batch file and there you can call your java class but before this save start time in variable and after class finish subtract
it with start time.
Upvotes: 0
Reputation: 15552
Wrap it in another class and run that. For example if your class (to which you dont have code) is called Runner then you may be currently running it as
java -jar jarContainingRunner.jar Runner
If you create another class that then calls Runner you can do anything in that class. For example you could call the class InstrumentedRunner.
public class InstrumentedRunner {
public static void main(String... arg) {
long start = System.currentTimeMillis();
new Runner().run();
long dur = System.currentTimeMillis() - start;
System.out.format("Runner took %s milliseconds", dur);
}
}
(I haven't tested the code above.)
You could then run
java -jar jarContainingRunner.jar;jarContainingInstrumentedRunner.jar instrumentedRunner
It would then run Runner's run method (assuming that is the method you want to time) and output the time it took.
Upvotes: 1