Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to measure loading time on the server and client sides

$
0
0
This example illustrates two approaches:

1. How to measure and display loading time on the sever using the System.Diagnostics.Stopwatch class:
CS:
[C#]
Stopwatchsw=System.Diagnostics.Stopwatch.StartNew();//some operationssw.Stop();AddEventLog(String.Format("Page_Load, Time: {0}",sw.Elapsed.TotalMilliseconds));privatevoidAddEventLog(stringeventLog){if(!String.IsNullOrEmpty(eventOrder))eventOrder+="<br/>";eventOrder+=eventLog;}
VB:
[VB.NET]
....Private sw As Stopwatch = System.Diagnostics.Stopwatch.StartNew()'some operations sw.Stop() AddEventLog(String.Format("Page_Load, Time: {0}", sw.Elapsed.TotalMilliseconds)) ...PrivateSub AddEventLog(ByVal eventLog AsString)If (NotString.IsNullOrEmpty(eventOrder)) Then eventOrder &= "<br/>"EndIf eventOrder += eventLogEndSub

All results are passed to the client-side for demonstration purposes.

2. How to measure rendering time on the client using JavaScript methods: 
     1) On the first page load create a Date variable in the head section.  
     2) Handle the ASPxClientGlobalEvents.ControlsInitialized event raised after our controls were loaded to check time difference. 
     3) I've overridden our internal aspxCallback function which is executed after the new result is applied from the client to define a start point on callbacks.

[JScript]
var start = new Date();function ge_ControlsInitialized(s, e){if(e.isCallback == false){var original = aspxCallback; aspxCallback = function(result, context){ start = new Date(); original(result, context);}}var end = new Date();var output = document.getElementById("output"); output.innerHTML = "Loading time(in ms): " + (end - start);}

Viewing all articles
Browse latest Browse all 7205

Trending Articles