import time import requests from threading import Thread from colorama import Fore, Style from queue import Queue def measure_ttfb(url, site_name, color, ttfb_queue): while True: start_time = time.perf_counter() response = requests.get(url) end_time = time.perf_counter() ttfb = end_time - start_time ttfb_ms = ttfb * 1000 print(f"{color}{site_name}: TTFB: {ttfb_ms:.2f} ms{Style.RESET_ALL}") ttfb_queue.put((site_name, ttfb_ms)) time.sleep(interval) def main(): sites = [ ("https://wordpress-193052-4604364.cloudwaysapps.com/wp-admin", "Staging", Fore.GREEN), ("https://contentsnare.com/wp-admin", "Production", Fore.BLUE), ("https://mythic-abyss-71810.wp1.site/wp-admin/", "Cloud Nine Web", Fore.CYAN), ] global interval interval = 5 # Interval in seconds ttfb_queue = Queue() threads = [] for site in sites: url, site_name, color = site thread = Thread(target=measure_ttfb, args=(url, site_name, color, ttfb_queue)) threads.append(thread) thread.start() while True: ttfb_values = [] for _ in range(len(sites)): site_name, ttfb_ms = ttfb_queue.get() ttfb_values.append((site_name, ttfb_ms)) lowest_ttfb = min(ttfb_values, key=lambda x: x[1]) lowest_site, lowest_ttfb_value = lowest_ttfb for site_name, ttfb_ms in ttfb_values: color = next((site[2] for site in sites if site[1] == site_name), None) print(f"{color}{site_name}: TTFB: {ttfb_ms:.2f} ms{Style.RESET_ALL}") lowest_color = next((site[2] for site in sites if site[1] == lowest_site), None) print(f"{lowest_color}{Style.BRIGHT}**{lowest_site}: TTFB: {lowest_ttfb_value:.2f} ms**{Style.RESET_ALL}") print("-" * 50) time.sleep(interval) if __name__ == "__main__": main()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter