Skip to content

Commit e87b7a7

Browse files
committed
microbench/profile: rename and few other scripts
1 parent dca6fae commit e87b7a7

File tree

11 files changed

+148
-93
lines changed

11 files changed

+148
-93
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,7 @@ docs/_build/
9494
microbench/pixi.lock
9595
microbench/.venv_*
9696
microbench/tmp_*
97-
microbench/profile_alloc/log
98-
microbench/profile_alloc/*.prof*
97+
microbench/profile/log*
98+
microbench/profile/*.prof*
99+
microbench/profile/*.log
100+
microbench/profile/callgrind.out.*

microbench/pixi.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ gcc = ">=15.1.0,<15.2"
1212
valgrind = ">=3.25.0,<4"
1313
libffi = ">=3.4.6,<4"
1414
libxcrypt = ">=4.4.36,<5"
15+
qcachegrind = ">=0.7.4,<0.8"

microbench/profile/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
clean:
3+
rm -f *.prof* logfile* callgrind.out.* tmp*

microbench/profile/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Profile
2+
3+
## Disable the JIT
4+
5+
```sh
6+
python --jit off profile_alloc.py
7+
```
8+
9+
## With vmprof
10+
11+
```sh
12+
pip install vmprof
13+
sudo apt install libunwind-dev
14+
python -m vmprof -o tmp_output.log profile_alloc.py
15+
vmprofshow tmp_output.log tree
16+
```
17+
18+
## with vmprof-firefox-converter
19+
20+
```sh
21+
pip install vmprof-firefox-converter
22+
vmprofconvert -run profile_alloc.py cpy
23+
# or
24+
vmprofconvert -run profile_alloc.py
25+
```
26+
27+
## With `PYPYLOG`
28+
29+
```sh
30+
PYPYLOG=jit-log-opt,jit-backend:logfile python profile_alloc_and_die.py
31+
```
32+
33+
## With Valgrind / Callgrind
34+
35+
```sh
36+
valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes python profile_alloc_and_die.py --short
37+
```
38+
39+
The Valgrind output (a file starting with "callgrind.out.") can for example be
40+
opened with `qcachegrind`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import gc
2+
3+
from time import perf_counter as time
4+
5+
from util import cls, N
6+
7+
8+
def main():
9+
objs = [None] * N
10+
for i in range(N):
11+
objs[i] = cls()
12+
return objs
13+
14+
15+
gc.collect()
16+
17+
t_start = time()
18+
main()
19+
print(f"time per allocation: {(time() - t_start)/N:.1e} s")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import gc
2+
3+
from time import perf_counter as time
4+
5+
from util import cls, N
6+
7+
8+
def main():
9+
for _ in range(N):
10+
obj = cls()
11+
obj.onearg(None)
12+
13+
14+
gc.collect()
15+
16+
t_start = time()
17+
main()
18+
print(f"time per allocation: {(time() - t_start)/N:.1e} s")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import gc
2+
3+
from time import perf_counter as time
4+
5+
from util import cls, N
6+
7+
8+
def main():
9+
objs = [None] * N
10+
for i in range(N):
11+
objs[i] = cls()
12+
return objs
13+
14+
15+
gc.collect()
16+
17+
t_start = time()
18+
_objs = main()
19+
del _objs
20+
gc.collect()
21+
print(f"time per object: {(time() - t_start)/N:.1e} s")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import gc
2+
3+
from time import perf_counter as time
4+
5+
from util import simple, N
6+
7+
8+
def main():
9+
for _ in range(N):
10+
simple.allocate_tuple()
11+
12+
gc.collect()
13+
14+
t_start = time()
15+
main()
16+
print(f"time per allocation: {(time() - t_start)/N:.1e} s")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import gc
2+
3+
from time import perf_counter as time
4+
5+
from util import cls, N
6+
7+
N *= 40
8+
9+
def main():
10+
obj = cls()
11+
for _ in range(N):
12+
# note: here we are NOT calling it, we want to measure just
13+
# the lookup
14+
obj.noargs # pylint: disable=W0104
15+
16+
17+
gc.collect()
18+
19+
t_start = time()
20+
main()
21+
print(f"time per lookup: {(time() - t_start)/N:.1e} s")
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
2-
import gc
31
import sys
42

5-
from time import perf_counter as time
6-
73
if "purepy" in sys.argv:
84
import purepy_simple as simple
95
elif "cpy" in sys.argv:
@@ -17,18 +13,12 @@
1713
print(simple)
1814

1915
cls = simple.HTFoo
16+
2017
N = 10000000
2118
if sys.implementation.name == "cpython":
2219
N *= 10
20+
elif sys.implementation.name == "pypy" and "cpy" in sys.argv:
21+
N *= 4
2322

24-
def main():
25-
objs = [None] * N
26-
for i in range(N):
27-
objs[i] = cls()
28-
return objs
29-
30-
gc.collect()
31-
32-
t_start = time()
33-
main()
34-
print(f"time per allocation: {(time() - t_start)/N:.1e} s")
23+
if "--short" in sys.argv:
24+
N //= 100

0 commit comments

Comments
 (0)