我的页面非常慢,我怎样才能确定它是 M、V 还是 C?什么样的计时机制才算准确?
控制器对模型进行几次调用,然后将一些数据返回到视图。实际上,可悲的是,该视图(这不是我的错)包含大量内联查询和更多对模型的调用,是的,我知道。无论如何,我的任务是优化这个非常慢的页面,并且我试图弄清楚如何判断哪件事花费了最多的时间。我只是想在页面所做的每个“事情”的开始和结束处放置一个计时器,并将它们输出到带有行号或其他内容的日志中。但不确定最准确的方法是什么。
//in controller
StartTimer();
var something = model.something.getsomething(someID);
StopTimerAndLog(3); //line number
<!-- in view -->
<%StartTimer();
var something = model.somethingelse.getanotherthing(someotherID);
StopTimerAndLog(2);%>
等等……
那么问题仍然是使用什么计时机制,我确信已经有一个关于这个的问题了。但我不知道我的情况是否有什么独特之处……有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你真的想这样测量,我会使用 StopWatch 类:
如果你想要一些非常详细的东西并且不需要编写任何额外的代码......我建议使用分析器。它将向您详细说明到底是什么花了这么长时间以及为什么。我个人最喜欢的是 RedGate 的 ANTS Performance Profiler。
If you really want to measure like this, I would use the StopWatch class:
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.