From d7ba90bbea24e07aa9be17eacf320d1bae05014b Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 20 Feb 2019 17:10:36 -0300 Subject: [PATCH] update ttfb script --- scripts/time_to_first_byte.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/scripts/time_to_first_byte.py b/scripts/time_to_first_byte.py index 74f72f028..ca12d045e 100644 --- a/scripts/time_to_first_byte.py +++ b/scripts/time_to_first_byte.py @@ -46,11 +46,11 @@ async def report_to_slack(output, webhook): pass -def confidence(times, z): +def confidence(times, z, plus_err=True): mean = sum(times) / len(times) standard_dev = (sum(((t - sum(times) / len(times)) ** 2.0 for t in times)) / len(times)) ** 0.5 err = (z * standard_dev) / (len(times) ** 0.5) - return f"{round(mean + err, 3)}s" + return f"{round((mean + err) if plus_err else (mean - err), 3)}" def variance(times): @@ -134,18 +134,17 @@ async def main(uris=None, allow_fees=False): await asyncio.sleep(0.1) print("**********************************************") - result = f"Tried to start downloading {len(resolvable)} streams from the front page\n" \ + result = f"Started {len(first_byte_times)} of {len(resolvable)} attempted front page streams\n" \ f"Worst first byte time: {round(max(first_byte_times), 2)}\n" \ f"Best first byte time: {round(min(first_byte_times), 2)}\n" \ - f"95% confidence time-to-first-byte: {confidence(first_byte_times, 1.984)}\n" \ - f"99% confidence time-to-first-byte: {confidence(first_byte_times, 2.626)}" \ + f"95% confidence time-to-first-byte: {confidence(first_byte_times, 1.984)}s\n" \ + f"99% confidence time-to-first-byte: {confidence(first_byte_times, 2.626)}s\n" \ f"Variance: {variance(first_byte_times)}\n" \ - f"Started {len(first_byte_times)}/{len(resolvable)} streams\n" \ f"Downloaded {len(download_successes)}/{len(resolvable)}\n" \ - f"Best stream download speed: {round(max(download_speeds), 2)}\n" \ - f"Worst stream download speed: {round(min(download_speeds), 2)}\n" \ - f"95% confidence download speed: {confidence(download_speeds, 1.984)}\n" \ - f"99% confidence download speed: {confidence(download_speeds, 2.626)}\n" + f"Best stream download speed: {round(max(download_speeds), 2)}mb/s\n" \ + f"Worst stream download speed: {round(min(download_speeds), 2)}mb/s\n" \ + f"95% confidence download speed: {confidence(download_speeds, 1.984, False)}mb/s\n" \ + f"99% confidence download speed: {confidence(download_speeds, 2.626, False)}mb/s\n" if failed_to_start: result += "\nFailed to start:" + "\n".join([f for f in failed_to_start])