in this article, i will show you calculate code execution time in asp.net mvc, which can be used to accurately measure the time taken for code execution. You don't need to use DateTime and calculate the time manually.
---Method---
public ActionResult Index()
{
var watch = new System.Diagnostics.Stopwatch();
watch.Start();
for (int i = 0; i < 100000000; i++)
{
}
watch.Stop();
ViewBag.TimeExecute = watch.ElapsedMilliseconds;
return View();
}
---View---
<h2>@ViewBag.TimeExecute ms</h2>
---Method---
public ActionResult Index()
{
var watch = new System.Diagnostics.Stopwatch();
watch.Start();
for (int i = 0; i < 100000000; i++)
{
}
watch.Stop();
ViewBag.TimeExecute = watch.ElapsedMilliseconds;
return View();
}
---View---
<h2>@ViewBag.TimeExecute ms</h2>
0 Comments