Answer the question
In order to leave comments, you need to log in
How to count the number of loop iterations in 1 second?
Greetings, a rather trivial task has appeared, but for half an hour I have been puzzling over its solution.
I need to count how many times the loop goes through in 1 second, in other words, the number of iterations per second, how can this be done?
Answer the question
In order to leave comments, you need to log in
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
int iterationCounter = 0;
while(true){
//todo
iterationCounter++;
if(stopWatch.ElapsedMilliseconds >= 1000){
Console.WriteLine("iterations "+iterationCounter);
break;
}
}
stopWatch.Stop();
var sw = new Stopwatch();
sw.Start();
<iterations>
sw.Stop();
mssec = sw.ElapsedMilliseconds;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question