Skip to content

Instantly share code, notes, and snippets.

@onewesong
Forked from mkaz/web_timing.py
Created March 24, 2022 09:47
Show Gist options
  • Save onewesong/7ba570aa43344d67c4cc20e0f5ed6846 to your computer and use it in GitHub Desktop.
Save onewesong/7ba570aa43344d67c4cc20e0f5ed6846 to your computer and use it in GitHub Desktop.
Use Selenium to Measure Web Timing
#!/usr/bin/env python
"""
Use Selenium to Measure Web Timing
Performance Timing Events flow
navigationStart -> redirectStart -> redirectEnd -> fetchStart -> domainLookupStart -> domainLookupEnd
-> connectStart -> connectEnd -> requestStart -> responseStart -> responseEnd
-> domLoading -> domInteractive -> domContentLoaded -> domComplete -> loadEventStart -> loadEventEnd
"""
from selenium import webdriver
source = "http://www.babycenter.com/"
driver = webdriver.Chrome()
driver.get(source)
navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
responseStart = driver.execute_script("return window.performance.timing.responseStart")
domComplete = driver.execute_script("return window.performance.timing.domComplete")
backendPerformance = responseStart - navigationStart
frontendPerformance = domComplete - responseStart
print "Back End: %s" % backendPerformance
print "Front End: %s" % frontendPerformance
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment