browser.py

Working through the exercises at browser.engineering
git clone https://git.sr.ht/~jbauer/browser.py
Log | Files | Refs | README | LICENSE

commit d32cbf1dfe66e6c99f3508ca75227bee54b8b9a6
parent 313909c1fa097467683a4af86658de6bfa26597c
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Tue, 21 Feb 2023 16:12:14 -0500

Add basic execution time printout

Diffstat:
Mbrowser.py | 32+++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/browser.py b/browser.py @@ -2,6 +2,7 @@ import tkinter import tkinter.font import socket import ssl +from timeit import default_timer as timer FONTS = {} @@ -9,6 +10,8 @@ WIDTH, HEIGHT = 800, 600 HSTEP, VSTEP = 13, 18 SCROLLSTEP = 100 +EXEC_TIME = 0 + class Browser: def __init__(self): self.scroll = 0 @@ -37,16 +40,28 @@ class Browser: def load(self, url): - print("Making request to", url) + overall_start = timer() + start = timer() headers, body = request(url) - print("Received response.") - print("Lexing response body...") + end = timer() + print('{0:.5f}'.format(end - start), "- Request to", url) + + start = timer() tokens = lex(body) - print("Laying out page...") + end = timer() + print('{0:.5f}'.format(end - start), "- Lexed response body") + + start = timer() self.display_list = Layout(tokens).display_list - print("Drawing canvas...") + end = timer() + print('{0:.5f}'.format(end - start), "- Computed page layout") + + start = timer() self.draw() - print("Done.") + end = timer() + print('{0:.5f}'.format(end - start), "- Canvas drawn") + + print('{0:.5f}'.format(timer() - EXEC_TIME), "- Time to first draw") def draw(self): @@ -216,6 +231,9 @@ def get_font(size, weight, slant): if __name__ == "__main__": + EXEC_TIME = timer() import sys - Browser().load(sys.argv[1]) + if len(sys.argv) < 2: url = "http://www.paritybit.ca/meta.html" + else: url = sys.argv[1] + Browser().load(url) tkinter.mainloop()