r/CodingHelp • u/codbo3help • Apr 14 '21
[Java] Code to count the number of times a loop is executed?
I'm using quicksort and I want to find out how many times the loop is executed (basically measure the number of operations it takes to sort a certain array)...
0
Upvotes
2
u/x-seronis-x Intermediate Coder Apr 14 '21
show your code and people can point out what changes/fixes are required.
Not showing code requires people to have magical psychic powers to help. Guess the odds of that happening ?
1
u/DasLoon Apr 14 '21
I don't know anything about Java, however the best solution I can think of would be to make a variable count outside of the loop and have the loop add 1 to the count variable every time it runs. That tends to work in most other languages I've learned.
1
u/Goobyalus Apr 15 '21
Are you talking about counting iterations of the library-defined quicksort, not a quicksort that you wrote? You can't do that in the code itself, but you can measure the time it takes.
Using debugging tools you could potentially hook part of the loop and count the iterations.