forked from pythonprofilers/memory_profiler
-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_gen.py
52 lines (38 loc) · 1.02 KB
/
test_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@profile
def my_func():
a = [1] * (10 ** 6)
b = [2] * (2 * 10 ** 7)
del b
yield a
@profile
def test_comprehension():
# Dict comprehension
d_comp = dict((str(k*k), [v] * (1<<17))
for (v, k) in enumerate(range(99, 111)))
# List comprehension
l_comp = [[i] * (i<<9) for i in range(99)]
del l_comp
del d_comp
def hh(x=1):
# Set comprehension
s_comp = set(('Z',) * (k<<13) for k in range(x, 19 + 2*x))
return s_comp
val = [range(1, 4), max(1, 4), 42 + len(hh())]
val = hh() | hh(4)
val.add(40)
l1_comp = [[(1, i)] * (i<<9) for i in range(99)]
l2_comp = [[(3, i)] * (i<<9) for i in range(99)]
return val
@profile
def test_generator():
a_gen = ([42] * (1<<20) for __ in '123')
huge_lst = list(a_gen)
b_gen = ([24] * (1<<20) for __ in '123')
del b_gen
del huge_lst
return a_gen
if __name__ == '__main__':
with profile:
next(my_func()) # Issue #42
test_generator()
test_comprehension()