Page Render Time in MVC

后端 未结 4 552
误落风尘
误落风尘 2021-02-06 05:45

Q: How do I calculate the total time it takes to render an MVC page and display the time on the master page.

In Asp.net Web Form I created a Base page class like so:

4条回答
  •  孤城傲影
    2021-02-06 06:44

    Go into your web.config and make sure you have...

    
        
    
    

    Then you can goto http://.../trace.axd and see every request made.

    Then you want to look under the From First(s) column and the very last one is the time it took to render the page (server side).

    Example...

    aspx.page   End Render  0.06121112  0.005297
    

    61.2 ms to render the page.

    If you're looking to time code itself or you want to manually do some diagnostics you want to use the System.Diagnostics.Stopwatch class not DateTime.

    Stopwatch sw = Stopwatch.StartNew();
    ...
    sw.Stop();
    Trace.Write(sw.ElapsedMilliseconds);
    

提交回复
热议问题