Which code segment should you use?

You use Microsoft .NET Framework 4 to develop an application that connects to a local Microsoft
SQL Server 2008 database. The application can access a high-resolution timer. You need to display
the elapsed time, in sub-milliseconds (<1 millisecond), that a database query takes to execute. Which
code segment should you use?

You use Microsoft .NET Framework 4 to develop an application that connects to a local Microsoft
SQL Server 2008 database. The application can access a high-resolution timer. You need to display
the elapsed time, in sub-milliseconds (<1 millisecond), that a database query takes to execute. Which
code segment should you use?

A.
int Scare = Environment.TickCount;
command.ExecuteNonQuery();

int Elapsed = (Environment.TickCount) = Start;
Console.WriteLine(“Time Elapsed: {0:N3} ins”, Elapsed);

B.
Stopwatch sw = Stopwatch.StartNew();
command.ExecuteNonQuery() ;
sw.Stop();
Console.WriteLine(“Time Elapsed: {0:N3} ms”,
sw.Elapsed.TotalHilliseconds);

C.
DateTime Start = DateTime.UtcNow;
command.ExecuteNonQuery();
TimeSpan Elapsed = DateTime.UtcNow = Start;
Console.WriteLine(“Time Elapsed: {0:N3} ms”,
Elapsed.Milliseconds);

D.
Stopwatch sw = new Stopwatch();
sw.Start() ;
command.ExecuteNonQuery();
sw.Stop();
Console. WriteLine (“Time Elapsed: {0:N3} ms”, sw.ElapsedHilliseconds);

Explanation:
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx



Leave a Reply 0

Your email address will not be published. Required fields are marked *