I have a function that sums two arrays element-wise and stops if the sum at a certain index is greater strictly than 1. This function is called lot of times (15817145 times for a small simulation and expects to grow a lot more as the simulation size grows). Profiling my code shows that it is among the five most consuming functions of my code and I believe can be optimized further.
def add_lis(lis1, lis2): res =  for i, j in zip(lis1, lis2): if i + j > 1: return res.append(i + j) return array('H', res)
lis2 are both of type
array.array('H',..). The two lists have the same length which can be up to 100 and they are both filled with zeroes and ones only. I tried with
numpy arrays but there is too much overhead that it is not beneficial to use it.
My question is can this function be optimized? Maybe in a sort of list comprehension ?