Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Measuring the execution time of a function, we get the following values:
1035, 1015, 1020, 1025, 1010

What is the average execution time of the function?

What I have tried:

I have used the Average Execution formula


1035+1015+1020+1025+1010 / 5 = 1020

But the Answer is Wrong here The program what i have used


Here is the C# program
C#
Stopwatch sw = new  
Stopwatch();
sw.Start();
f();
sw.Stop();
Console.WriteLine(sw.Elapsed);
Posted
Updated 4-Mar-17 18:20pm
v3
Comments
PIEBALDconsult 5-Mar-17 0:41am    
Order of operations and integer math.

1 solution

Use .TotalMilliseconds. Divide by 1000 (1000 milliseconds = 1 second) if you want number of seconds...

C#
Stopwatch sw = new Stopwatch();
sw.Start();
f();
sw.Stop();
Console.WriteLine($"{sw.TotalMilliseconds / 1000} seconds");
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900