cProfile python (benchmark)

Python includes a profiler called cProfile. It not only gives the total running time, but also times each function separately, and tells you how many times each function was called, making it easy to determine where you should make optimizations.

For example, you can invoke the cProfile when running a script with the following:

python -m cProfile myscript.py  

the output of this script look like this below:

4550013 function calls in 4.187 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.002    0.002    4.187    4.187 my_trans.py:1(<module>)
      297    0.002    0.000    0.002    0.000 my_trans.py:107(max_location_row)
      297    0.003    0.000    0.003    0.000 my_trans.py:117(max_location_cols)
      594    0.002    0.000    0.022    0.000 my_trans.py:127(find_pivot)
        1    0.006    0.006    0.008    0.008 my_trans.py:14(rows_dict)
        1    0.010    0.010    4.165    4.165 my_trans.py:146(main)
        1    0.006    0.006    0.008    0.008 my_trans.py:24(cols_dict)
    45078    2.611    0.000    4.013    0.000 my_trans.py:34(two_mins)
        1    0.000    0.000    0.000    0.000 my_trans.py:5(Vogel)
      297    0.037    0.000    2.118    0.007 my_trans.py:54(diff_r)
        1    0.000    0.000    0.000    0.000 my_trans.py:7(__init__)
      297    0.055    0.000    1.987    0.007 my_trans.py:71(diff_c)
      297    0.006    0.000    0.006    0.000 my_trans.py:88(find_max)
        1    0.000    0.000    0.000    0.000 timeit.py:105(Timer)
        1    0.000    0.000    0.000    0.000 timeit.py:53(<module>)
        1    0.000    0.000    0.000    0.000 txtdata.py:1(<module>)
        1    0.000    0.000    0.000    0.000 txtdata.py:1(warehouses_construction)
        1    0.000    0.000    0.000    0.000 txtdata.py:16(stores_construction)
        1    0.000    0.000    0.000    0.000 txtdata.py:31(supply_construction)
        1    0.000    0.000    0.000    0.000 txtdata.py:46(demand_construction)
        1    0.015    0.015    0.018    0.018 txtdata.py:60(cost_construction)
    45072    0.006    0.000    0.006    0.000 {abs}
    92044    0.012    0.000    0.012    0.000 {len}
        4    0.000    0.000    0.000    0.000 {map}
  4272686    0.349    0.000    0.349    0.000 {method 'append' of 'list' objects}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
      646    0.004    0.000    0.004    0.000 {method 'index' of 'list' objects}
      104    0.001    0.000    0.001    0.000 {method 'split' of 'str' objects}
     1420    0.016    0.000    0.016    0.000 {min}
        5    0.000    0.000    0.000    0.000 {open}
    45780    0.057    0.000    0.057    0.000 {range}
    45078    0.986    0.000    0.986    0.000 {sorted}
        2    0.000    0.000    0.000    0.000 {time.time}

Comments

Popular posts from this blog

Vertex Cover (python implementation)

Transportation Problem (Vogel algorithm python)

IP scanning in python