Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How long does my code take to run?

How can I find out how much time my C# code takes to run?

like image 376
Vahid.m Avatar asked Aug 16 '09 18:08

Vahid.m


People also ask

How can I tell how long a code will run?

A way you can figure it out is writing that line of code 1000 times and then time how long it takes to run that code and then dividing the time by 1000, to get a more acurate time you can run that test 10 times and see the average time you got out of all those tests.

Which module can say how long your code took to run?

This module provides a simple way to time small bits of Python code.

What does %% time mean in Python?

%%time is a magic command. It's a part of IPython. %%time prints the wall time for the entire cell whereas %time gives you the time for first line only. Using %%time or %time prints 2 values: CPU Times.


1 Answers

Check out the Stopwatch class:

Stopwatch sw = new Stopwatch();
sw.Start();

// your code here

sw.Stop();
TimeSpan elapsedTime = sw.Elapsed;
like image 173
Fredrik Mörk Avatar answered Oct 15 '22 03:10

Fredrik Mörk