I want to get the maximum count I have to execute a loop for it to take x milliseconds to finish.
For eg.
int GetIterationsForExecutionTime(int ms) {
You could also use the Stopwatch class:
int GetIterationsForExecutionTime(int ms) { int count = 0; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { // some code here count++; } while (stopwatch.ElapsedMilliseconds < ms); stopwatch.Stop(); return count; }