Skip to content

Instantly share code, notes, and snippets.

@csy1204
Last active May 5, 2020 14:37
Show Gist options
  • Save csy1204/481d4250e76c3833b62afd5e5b9bad5f to your computer and use it in GitHub Desktop.
Save csy1204/481d4250e76c3833b62afd5e5b9bad5f to your computer and use it in GitHub Desktop.
HTTP vs HTTP3 Performance Comparison
import time
import pandas as pd
import numpy as np
from selenium import webdriver
def get_timing_performance(t):
return {
"DNS_time": t['domainLookupEnd'] - t['domainLookupStart'],
"INIT_CNT_time": t['connectEnd'] - t['connectStart'],
"SSL_time": t['connectEnd'] - t['secureConnectionStart'],
"TTFB_time": t['responseStart'] - t['requestStart'],
"CONTENT_DL_time": t['responseEnd'] - t['responseStart'],
"DOM_COMPL_time": t["domComplete"] - t['responseEnd'],
"TOT_time": t["domComplete"] - t['domainLookupStart']
}
get_perf = lambda driver: get_timing_performance(driver.execute_script("return window.performance.timing"))
http3_support_sites = [
"https://www.google.com",
"https://earth.google.com",
"https://www.google.com/maps",
"https://play.google.com",
"https://artsandculture.google.com"
]
def hard_refresh(driver):
driver.execute_script("location.reload(true);")
def test_site_by_driver(driver, rounds=9, sleep=3, refresh_hard=True, sites=http3_support_sites):
result = []
for site_url in sites:
driver.get(site_url)
r = get_perf(driver)
r["site"], r["try"] = site_url, 0
result.append(r)
for t in range(rounds):
hard_refresh(driver) if refresh_hard else driver.refresh()
r = get_perf(driver)
r["site"], r["try"] = site_url, t + 1
result.append(r)
time.sleep(sleep)
return pd.DataFrame(result)
# HTTP 일반 연결
fp = get_http3_profile(False)
driver = webdriver.Firefox(executable_path='./geckodriver', firefox_profile=fp)
df_http = test_site_by_driver(driver, rounds=9, sleep=1, refresh_hard=False)
driver.quit()
# HTTP3 연결 사용
fp = get_http3_profile(True)
driver_http3 = webdriver.Firefox(executable_path='./geckodriver', firefox_profile=fp)
df_http3 = test_site_by_driver(driver_http3, rounds=9, sleep=1, refresh_hard=False)
driver.quit()
# HTTP3, HTTP 연결 시간 차이 테이블 생성
time_cols = ['DNS_time','INIT_CNT_time','SSL_time','TTFB_time', 'CONTENT_DL_time',"DOM_COMPL_time","TOT_time"]
df_diff = df_http3[time_cols] - df_http[time_cols]
df_diff3[["site", "try"]] = df_http2[["site", "try"]]
ptable = df_diff3.pivot_table(time_cols, ["site"], aggfunc=np.mean)
ptable = ptable[['DNS_time','INIT_CNT_time','SSL_time','TTFB_time', 'CONTENT_DL_time',"DOM_COMPL_time","TOT_time"]]
ptable.columns = ['DNS Lookup','첫 연결 시간',
'SSL 보안', 'TTFB(첫 응답시간)', '콘텐츠 다운 시간',
'DOM완료 시간', '전체 시간']
print(ptable) #display(ptable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment