c# - Calculate execution time of one or more lines of code -


is there way (a class-made in c #) that allow me to calculate the time required to execute some lines in program.

ex :

try {   string connectionstring = getconnectionstring();   using (sqlconnection conn = new sqlconnection(connectionstring))   {     conn.open();      ***// start counting:      // time = 0***       using (sqlcommand cmd = new sqlcommand(      “select * books”, conn))       using (sqldatareader reader = cmd.executereader())        {          while (reader.read())           {              console.writeline(“{0}\t{1}\t{2}”,               reader.getint32(0),              reader.getstring(1),               reader.getint32(2));           }     ***// end counting     // time = 10 sec***   } }  

one option use built-in stopwatch class:

var sw = stopwatch.startnew();  //  sw.stop(); console.writeline("time elapsed: {0} milliseconds", sw.elapsedmilliseconds); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -