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.
解决方案
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.