File: test_precision_import.py

package info (click to toggle)
python-memory-profiler 0.61-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 540 kB
  • sloc: python: 2,220; makefile: 33
file content (37 lines) | stat: -rw-r--r-- 842 bytes parent folder | download | duplicates (5)
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
# .. an example to test decorator with precision keyword argument ..
"""
Test profiling using imported ``profile`` function with precision
specified as parameter to ``profile`` function.
This is useful if the python script we're trying to profile is called as a
module (like `python -m test_module`) and so we can't specify command line
precision parameter.
"""

import time
from memory_profiler import profile

@profile(precision=4)
def test_1():
    a = [1] * (10 ** 6)
    b = [2] * (2 * 10 ** 7)
    time.sleep(0.6)
    del b

    for i in range(2):
        a = [1] * (10 ** 6)
        b = [2] * (2 * 10 ** 7)
        del b
    return a

@profile(precision=5)
def test_2():
    a = {}
    time.sleep(0.5)
    for i in range(10000):
        a[i] = i + 1
    time.sleep(0.6)
    return

if __name__ == '__main__':
    test_1()
    test_2()