我的页面非常慢,我怎样才能确定它是 M、V 还是 C?什么样的计时机制才算准确?

发布于 2024-10-12 15:39:40 字数 549 浏览 7 评论 0原文

控制器对模型进行几次调用,然后将一些数据返回到视图。实际上,可悲的是,该视图(这不是我的错)包含大量内联查询和更多对模型的调用,是的,我知道。无论如何,我的任务是优化这个非常慢的页面,并且我试图弄清楚如何判断哪件事花费了最多的时间。我只是想在页面所做的每个“事情”的开始和结束处放置一个计时器,并将它们输出到带有行号或其他内容的日志中。但不确定最准确的方法是什么。

//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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两个我 2024-10-19 15:39:40

如果你真的想这样测量,我会使用 StopWatch 类

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

var time = watch.Elapsed;

如果你想要一些非常详细的东西并且不需要编写任何额外的代码......我建议使用分析器。它将向您详细说明到底是什么花了这么长时间以及为什么。我个人最喜欢的是 RedGate 的 ANTS Performance Profiler

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文