如何跟踪MVC3代码块执行的时间?

时间:2021-08-11 07:39:19

My MVC3 application is not running as fast as I hoped. I'd like to find out if some of the database look ups are taking too long. Is there a way that I can time part of a block of code within a controller. For example:

我的MVC3应用程序没有我希望的那么快。我想知道一些数据库查找是否花费了太多的时间。是否有一种方法可以让我在控制器中计时一段代码。例如:

var a = the_time_now;
...
...
var b = the_time_now;

<log the code area name and time b - time a 

I am fairly new to MVC and would appreciate any advice. Note that I currently have no uses on my system so if I was logging the time then it would not load things down too much :-)

我是MVC的新手,希望能得到您的建议。请注意,我目前在我的系统上没有使用,所以如果我记录时间,那么它就不会加载太多东西:-)

1 个解决方案

#1


2  

Use the Stopwatch class for the code execution time tracking. this is not titly bound to MVC, this is used generally in .net Framework

使用Stopwatch类跟踪代码的执行时间。这并不局限于MVC,这在。net框架中很常见

#1


2  

Use the Stopwatch class for the code execution time tracking. this is not titly bound to MVC, this is used generally in .net Framework

使用Stopwatch类跟踪代码的执行时间。这并不局限于MVC,这在。net框架中很常见