Skip to content

Commit

Permalink
Add CPU timing to benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Feb 28, 2023
1 parent 4d432a7 commit 9398c96
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions examples/benchmark/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import time
from timeit import timeit
import requests
import psutil
import humanize
Expand Down Expand Up @@ -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)

0 comments on commit 9398c96

Please sign in to comment.