From 9398c960752f87bc32d7c4349cbf594e5d678e99 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 28 Feb 2023 23:30:58 +0000 Subject: [PATCH] Add CPU timing to benchmark --- examples/benchmark/run.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/benchmark/run.py b/examples/benchmark/run.py index 14c321d..de4099b 100644 --- a/examples/benchmark/run.py +++ b/examples/benchmark/run.py @@ -1,6 +1,7 @@ import os import subprocess import time +from timeit import timeit import requests import psutil import humanize @@ -81,14 +82,18 @@ stderr=subprocess.DEVNULL ) time.sleep(1) + tm = 0 if not name.startswith('baseline'): - r = requests.get('http://localhost:5000') - r.raise_for_status() + def req(): + r = requests.get('http://localhost:5000') + r.raise_for_status() + + tm = timeit(req, number=1000) proc = psutil.Process(p.pid) mem = proc.memory_info().rss for child in proc.children(recursive=True): mem += child.memory_info().rss bar = '*' * (mem // (1024 * 1024)) - print(f'{name:<28}{humanize.naturalsize(mem):>10} {bar}') + print(f'{name:<28}{tm:10.2f}s {humanize.naturalsize(mem):>10} {bar}') p.terminate() time.sleep(1)