robmcmullen / omnivore

Hex editor and debugging emulator, sponsored by the Player/Missile Podcast
Mozilla Public License 2.0
53 stars 7 forks source link

speed up get_comments_in_range #126

Closed robmcmullen closed 7 years ago

robmcmullen commented 7 years ago

with call to get_comments_in_range:

function called 11 times

         3623568 function calls (3387231 primitive calls) in 6.392 seconds

   Ordered by: cumulative time, internal time, call count
   List reduced from 49 to 40 due to restriction <40>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       11    0.000    0.000    6.392    0.581 disasm.py:76(disassemble_segment)
       11    0.007    0.001    6.355    0.578 segments.py:467(get_entire_style_ranges)
      351    0.670    0.002    6.339    0.018 segments.py:673(get_comments_in_range)
   385047    0.960    0.000    5.669    0.000 segments.py:423(get_index_from_base_index)
   385047    1.070    0.000    4.349    0.000 segments.py:185(get_raw_index)
   623096    2.697    0.000    3.279    0.000 utils.py:185(byte_bounds)
   623096    0.447    0.000    0.582    0.000 numeric.py:406(asarray)
   385047    0.111    0.000    0.360    0.000 segments.py:414(is_valid_index)
355279/119019    0.159    0.000    0.250    0.000 {len}
   118130    0.046    0.000    0.171    0.000 segments.py:398(__len__)
   623107    0.135    0.000    0.135    0.000 {numpy.core.multiarray.array}
   118130    0.045    0.000    0.061    0.000 segments.py:148(__len__)
       11    0.027    0.002    0.037    0.003 __init__.py:208(get_all)
       11    0.000    0.000    0.007    0.001 shape_base.py:436(split)
       11    0.003    0.000    0.007    0.001 shape_base.py:378(array_split)
      843    0.005    0.000    0.005    0.000 {method 'get' of 'dict' objects}

without:

function called 11 times

         9458 function calls (9359 primitive calls) in 0.092 seconds

   Ordered by: cumulative time, internal time, call count
   List reduced from 43 to 40 due to restriction <40>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       11    0.001    0.000    0.092    0.008 disasm.py:76(disassemble_segment)
       11    0.053    0.005    0.070    0.006 __init__.py:208(get_all)
       11    0.010    0.001    0.021    0.002 segments.py:467(get_entire_style_ranges)
      916    0.010    0.000    0.010    0.000 {method 'get' of 'dict' objects}
       11    0.000    0.000    0.008    0.001 shape_base.py:436(split)
       11    0.004    0.000    0.008    0.001 shape_base.py:378(array_split)
       11    0.002    0.000    0.004    0.000 __init__.py:66(copy_resize)
       11    0.000    0.000    0.003    0.000 __init__.py:202(clear)
       11    0.003    0.000    0.003    0.000 __init__.py:44(clear)
     1025    0.001    0.000    0.003    0.000 fromnumeric.py:451(swapaxes)
       11    0.000    0.000    0.002    0.000 {method 'view' of 'numpy.ndarray' objects}
     1025    0.002    0.000    0.002    0.000 {method 'swapaxes' of 'numpy.ndarray' objects}
       11    0.000    0.000    0.002    0.000 _internal.py:451(_view_is_safe)
       11    0.001    0.000    0.001    0.000 _internal.py:372(_check_field_overlap)

So clearly teh naive approach in get_comments_in_range is too slow!

robmcmullen commented 7 years ago

Obviated by the fix for #125