CPU can do multiple operation at the same time with no additional cost on time or performance. Use vectorization to utilize this. possible with libraries such as 'numpy'.
Design your code in such a way that to minimize CPU moving data from RAM to L2 cache and minimize number of reads CPU has to perform from RAM.
Natively python can't make use of multiple CPU core. Inorder to avoid this problem use multiprocessing instead of multiple threads.
line_profiler profile a given function line by line.
heapy a track all objects in Python memory.
perf stat to see number of instructions ultimately executed by CPU.
memory_profile to show memory usage.
#python -m timeit -n 5 -r 5 "import test"
5 loops, best of 5: 0.763 usec per loop
simple timing using unix time command : time -p python test.py
or you can use cProfile
$ python -m cProfile -s cumulative test.py
3 function calls in 0.002 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.002 0.002 0.002 0.002 test.py:1(<module>)
1 0.000 0.000 0.000 0.000 {range}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
This gives cumulative time of each function
within the code, you can use 'import timeit' module for timing.
Design your code in such a way that to minimize CPU moving data from RAM to L2 cache and minimize number of reads CPU has to perform from RAM.
Natively python can't make use of multiple CPU core. Inorder to avoid this problem use multiprocessing instead of multiple threads.
line_profiler profile a given function line by line.
heapy a track all objects in Python memory.
perf stat to see number of instructions ultimately executed by CPU.
memory_profile to show memory usage.
#python -m timeit -n 5 -r 5 "import test"
5 loops, best of 5: 0.763 usec per loop
simple timing using unix time command : time -p python test.py
or you can use cProfile
$ python -m cProfile -s cumulative test.py
3 function calls in 0.002 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.002 0.002 0.002 0.002 test.py:1(<module>)
1 0.000 0.000 0.000 0.000 {range}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
This gives cumulative time of each function
within the code, you can use 'import timeit' module for timing.
No comments:
Post a Comment