User Tools

Site Tools


competitive_programming:development_utilities

Profiling Tools

Python

cProfile

>>> import cProfile
>>> cProfile.run('x = [i for i in range(10000000)]')
         4 function calls in 0.719 seconds
 
   Ordered by: standard name
 
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.568    0.568    0.568    0.568 <string>:1(<listcomp>)
        1    0.151    0.151    0.719    0.719 <string>:1(<module>)
        1    0.000    0.000    0.719    0.719 {built-in method exec}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
profile.py
def foo(iters):
    x = 0
    for i in range(iters):
        x += 1
 
def bar(iters):
    x = 0
    for i in range(iters):
        x += 1
 
def baz(iters):
    x = 0
    for i in range(iters):
        x += 1
 
 
if __name__ == "__main__":
    foo(10000)
    bar(100000)
    baz(1000000)
$ python -m cProfile -s cumtime profile.py
         8 function calls in 0.059 seconds
 
   Ordered by: cumulative time
 
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.059    0.059 profile.py:1(<module>)
        1    0.035    0.035    0.054    0.054 profile.py:11(baz)
        3    0.021    0.007    0.021    0.007 {range}
        1    0.003    0.003    0.005    0.005 profile.py:6(bar)
        1    0.000    0.000    0.000    0.000 profile.py:1(foo)
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

Debugging Tools

Memory Leak Detection

Valgrind
competitive_programming/development_utilities.txt · Last modified: 2018/09/12 14:49 by jguerin