Skip to content

Commit 9dc9557

Browse files
authored
Merge pull request #3 from ericsnowcurrently/pyperformance
Use pyperformance to run the benchmarks.
2 parents 96730b0 + 766642a commit 9dc9557

File tree

115 files changed

+1580
-694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+1580
-694
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,4 @@ dmypy.json
129129
.pyre/
130130

131131
results
132+
benchmarks/bm_pytorch_alexnet_inference/data/dog.jpg

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
11
# python-macrobenchmarks
22
A collection of macro benchmarks for the Python programming language
3+
4+
5+
## usage
6+
7+
```shell
8+
# Run the default benchmarks:
9+
python3 -m pyperformance run --manifest $PWD/benchmarks/MANIFEST
10+
```
11+
12+
The benchmarks can still be run without pyperformance. This will produce
13+
the old results format.
14+
15+
```shell
16+
# Run the benchmarks:
17+
sh ./run_all.sh
18+
19+
# Run the mypy benchmark using mypyc:
20+
sh ./run_mypy.sh
21+
```

benchmarks/.libs/legacyutils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import json
2+
import sys
3+
4+
5+
def maybe_handle_legacy(bench_func, *args, loopsarg='loops', legacyarg=None):
6+
if '--legacy' not in sys.argv:
7+
return
8+
argv = list(sys.argv[1:])
9+
argv.remove('--legacy')
10+
11+
kwargs = {}
12+
if legacyarg:
13+
kwargs[legacyarg] = True
14+
if argv:
15+
assert loopsarg
16+
kwargs[loopsarg] = int(argv[0])
17+
18+
_, times = bench_func(*args, **kwargs)
19+
if len(argv) > 1:
20+
json.dump(times, open(argv[1], 'w'))
21+
22+
sys.exit(0)

benchmarks/.libs/netutils.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import contextlib
2+
import ipaddress
3+
import os.path
4+
import socket
5+
import subprocess
6+
import time
7+
8+
9+
@contextlib.contextmanager
10+
def serving(argv, sitedir, addr, *,
11+
pause=None,
12+
kill=False,
13+
quiet=True,
14+
):
15+
if os.path.exists(addr):
16+
sock = addr
17+
addr = None
18+
try:
19+
os.remove(sock)
20+
except FileNotFoundError:
21+
pass
22+
else:
23+
sock = None
24+
25+
p = subprocess.Popen(
26+
argv,
27+
cwd=sitedir,
28+
stdout=subprocess.DEVNULL if quiet else None,
29+
stderr=subprocess.STDOUT if quiet else None,
30+
)
31+
try:
32+
if pause:
33+
time.sleep(pause)
34+
if not sock:
35+
try:
36+
waitUntilUp(addr)
37+
except NotImplementedError:
38+
sock = addr
39+
addr = None
40+
if sock:
41+
while not os.path.exists(sock):
42+
time.sleep(0.001)
43+
assert p.poll() is None, p.poll()
44+
yield
45+
assert p.poll() is None, p.poll()
46+
finally:
47+
p.terminate()
48+
if kill:
49+
p.kill()
50+
p.wait()
51+
52+
53+
def waitUntilUp(addr, timeout=10.0):
54+
end = time.time() + timeout
55+
addr = parse_socket_addr(addr)
56+
started = False
57+
current = time.time()
58+
while not started or current <= end:
59+
try:
60+
with socket.create_connection(addr) as sock:
61+
return
62+
except ConnectionRefusedError:
63+
time.sleep(0.001)
64+
started = True
65+
current = time.time()
66+
raise Exception('Timeout reached when trying to connect')
67+
68+
69+
def parse_socket_addr(addr, *, resolve=True):
70+
if not isinstance(addr, str):
71+
raise NotImplementedError(addr)
72+
host, _, port = addr.partition(':')
73+
74+
if not host:
75+
raise NotImplementedError(addr)
76+
try:
77+
host = ipaddress.ip_address(host)
78+
except ValueError:
79+
raise NotImplementedError(addr)
80+
host = str(host)
81+
82+
if not port:
83+
raise NotImplementedError(addr)
84+
if not port.isdigit():
85+
raise NotImplementedError(addr)
86+
port = int(port)
87+
88+
return (host, port)

benchmarks/MANIFEST

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[benchmarks]
2+
3+
name metafile
4+
aiohttp <local>
5+
djangocms <local>
6+
flaskblogging <local>
7+
gevent_hub <local>
8+
gunicorn <local>
9+
json <local>
10+
kinto <local>
11+
mypy <local>
12+
mypyc <local:mypy>
13+
pycparser <local>
14+
pylint <local>
15+
pytorch_alexnet_inference <local>
16+
thrift <local>
17+
18+
[group default]
19+
-mypyc

benchmarks/aiohttp.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

benchmarks/base.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../pyproject.toml
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../.libs/legacyutils.py

benchmarks/bm_aiohttp/netutils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../.libs/netutils.py

0 commit comments

Comments
 (0)