basse basse - 9 months ago 24
Java Question

What is the preferred way of iterating over main()?

I have a main() method that essentially plays a game with some random elements in it. For a school project, I'm developing an algorithm to play the game and would like to measure the performance changes as I progress with the program. Thus, I need to iterate over main() a large number of times and record analytics data of each run.

What is the preferred method of doing this? I can, of course, embed the original contents of main() in a

loop and add the analytics calls in and after that. However, I have a kind of a gut feeling that there is a better and (since I'm studying this stuff) more professional way. Also, I'd like to keep the original program as unchanged as possible.

Or would it be better to discard implementing this into the actual program itself and look at perhaps the IDE doing the iteration by just running the program from start to finish many times?

As always, big thanks!

Answer Source

Create a second class named <your-main-classname>PerfTest, code a second static main method in it and from the inner loop call <your-main-classname>.main( args ).