我有一个很慢的页面,我怎么能算出来是M V C呢?什么样的定时机制是准确的?

时间:2021-08-20 21:10:37

The controller makes a few calls to the model, then it returns some data to the view. The view actually, sadly, (it's not my fault), contains a ton of inline queries and more calls to the Model, yeah I know. Anyways I am tasked with optimizing this really slow page and I am trying to figure out how I can tell which thing is taking the most time. I was just going to put a timer at the start and the end of each 'thing' that the page does and output them to a log with the line number or something. But not sure what the most accurate way to do this is.

控制器对模型进行一些调用,然后向视图返回一些数据。实际上,遗憾的是(这不是我的错),包含了大量的内联查询和对模型的更多调用,是的,我知道。不管怎么说,我的任务是优化这个很慢的页面,我想弄清楚我怎么才能知道哪个东西花费的时间最多。我只是要在页面的开始和结束处设置一个计时器并将它们输出到带有行号的日志中。但不确定最准确的方法是什么。

//in controller
StartTimer();
var something = model.something.getsomething(someID);
StopTimerAndLog(3); //line number

<!-- in view -->
<%StartTimer();
var something = model.somethingelse.getanotherthing(someotherID);
StopTimerAndLog(2);%>

so on and so forth...

等等……

Then the question remains about what timing mechanism to use, I'm sure there must be a question about this already. But I don't know if my situation makes anything unique or not... any ideas?

那么问题仍然是使用什么时间机制,我肯定已经有了这个问题。但我不知道我的处境是否让我与众不同……什么好主意吗?

1 个解决方案

#1


6  

If you really want to measure like this, I would use the StopWatch class:

如果你真的想这样测量,我会用秒表类:

var watch = new StopWatch();
watch.Start();
var something = model.something.getSomething(someID);
watch.Stop();

var time = watch.Elapsed;

If you want something really detailed and without writing any extra code...I would suggest the use of a Profiler. It will give you details about exactly what is taking so long and why. My personal favorite is RedGate's ANTS Performance Profiler.

如果您想要一些非常详细的东西,而不需要编写任何额外的代码……我建议使用分析器。它会告诉你为什么要花这么长时间。我个人最喜欢的是RedGate的蚂蚁性能分析器。

#1


6  

If you really want to measure like this, I would use the StopWatch class:

如果你真的想这样测量,我会用秒表类:

var watch = new StopWatch();
watch.Start();
var something = model.something.getSomething(someID);
watch.Stop();

var time = watch.Elapsed;

If you want something really detailed and without writing any extra code...I would suggest the use of a Profiler. It will give you details about exactly what is taking so long and why. My personal favorite is RedGate's ANTS Performance Profiler.

如果您想要一些非常详细的东西,而不需要编写任何额外的代码……我建议使用分析器。它会告诉你为什么要花这么长时间。我个人最喜欢的是RedGate的蚂蚁性能分析器。