0 votes
1 view
in Machine Learning by (13.4k points)
How can I measure the speed of code written in Java?

I planning to develop software which will solve Sudoku using all presently available AI and ML algorithms and compare time against the simple brute-force method. I need to measure the time of each algorithm, I would like to ask for suggestions on what is the best way of doing that? Very important, the program must be useful on any machine regardless of CPU power/memory.

Thank you.

1 Answer

0 votes
by (32.8k points)

You can simply use

System.currentTimeMillis()

to calculate deltas of time:

long start = System.currentTimeMillis();

long elapsed = System.currentTimeMillis() - start;

Mind that depending on the operating system you use the precision of the funcion could be greater than 1 millisecond (also tenth of msecs) so you'll have to tweak it to be useful for your analysis.

You can also use System.nanoTime() but you don't have any guarantee that accuracy will be of nanoseconds.

Hope this answer helps you!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...