Search This Blog

Monday, July 29, 2013

Page Load time using VB Script

url = "http://www.anyurl.com/"
Set dom = CreateObject ("InternetExplorer.Application") 'Create an IE object
Set dom = WScript.CreateObject("InternetExplorer.Application", "dom_")
Dom.Visible = True
dom.Navigate (url) 'open the specified URL
time_start = Now () 'Get the statistics at the beginning of time
timer_start = Timer () 'Get the number of milliseconds for the current time
a = dom.ReadyState 'Get the current IE status value, the state will use the value judgments IE the current state of
dom.visible = True 'to set IE visible
While dom.busy or (dom.readyState <> 4) 'when IE is BUSY or loaded unfinished (readyState is not equal to 4), according to the the IE state of statistical time, once every millisecond Statistics
WScript.Sleep (1) 'interval of 1 ms, if the time interval is relatively long, it is likely to take less than state value
Select Case dom.readystate 'judgment dom.readystate value
 Case 0 'IE is not initialized, in fact, in this method, readyState = 0 meaningless, because the loop is at least starting from 1.
  time0 = Now ()
  timer0 = timer ()
 Case 1 '"Sending request"
  Time1 = Now ()
  timer1 = timer ()
 Case 2 'request has been sent to complete "
  time2 = Now ()
  timer2 = timer ()
 Case 3 'can be received part of the response data "
  time3 = Now ()
  Timer3 = timer ()
 Case 4 'page is loaded
  time4 = now ()
  timer4 = timer ()
 End Select
wend
time_end = Now () 'statistics time
MsgBox "start time is:" & time1 & "; End Time" & time2
timeCount = "Statistics start time:" & start_time & vbCrLf & "time0:" & TIME0 & vbcrlf & "Time1:" & time1 & vbcrlf & "time2:" & time2 & vbcrlf & "Time3:" & time3 & vbcrlf & "time4:" & time4 & vbcrlf & "To complete the IE initialization and send the request:" & (timer1-timer_start) & "seconds" & vbcrlf & "Send completed and accepted part of the server response data: "& (timer3-timer1) &" "& vbcrlf & "100% to receive and complete the parsing of HTML content:" & (timer4-timer3 &"seconds") & "" & vbcrlf & "Spent a total of:" & (timer4-timer_start) & "seconds"
msgbox timeCount