Created
January 17, 2019 14:20
-
-
Save ptigas/f2a13948f2222b98919a9a9e1ae7b50f to your computer and use it in GitHub Desktop.
analyse_performance.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sys | |
import pandas as pd | |
import glob | |
def analyse(files): | |
''' | |
- latency (responseStart - requestStart) | |
- time to interactive (domInteractive - navigationStart) | |
- load time (loadEventStart - navigationStart) | |
- first meaningful paint | |
''' | |
N_bins = 4 | |
print("Files in analysis: {}".format(len(files))) | |
analysis_results = [] | |
for _file in files: | |
data = json.load(open(_file)) | |
res = [] | |
for row in data: | |
res.append({ | |
'number_of_images': row['number_of_images'], | |
'latency': row['requestStart'] - row['requestStart'], | |
'render': row['domComplete'] - row['domLoading'], | |
'time_to_interactive': row['domInteractive'] - row['navigationStart'], | |
'load_time': row['loadEventStart'] - row['navigationStart'], | |
'first_meaningful_paint': row['firstMeaningfulPaint'], | |
'url': row['url'] | |
}) | |
df = pd.DataFrame(res) | |
df['number_of_images_bin'] = pd.cut(df['number_of_images'], N_bins) | |
per_json_analysis = df.groupby(df['number_of_images_bin'])\ | |
.agg(['mean'])\ | |
.reset_index() | |
per_json_analysis['file'] = _file | |
analysis_results.append(per_json_analysis) | |
analysis_df = pd.concat(analysis_results) | |
print(analysis_df.groupby(analysis_df['number_of_images_bin']).agg(['mean', 'std'])) | |
if __name__ == '__main__': | |
analyse(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment