I have a script where I am computing:
def sumsquared(arr):
sum = 0
idx = 0
len = arr.__len__()
while idx < (len - 1):
sum = sum + (arr[idx] * arr[idx]) + (arr[idx+1] * arr[idx+1])
idx = idx + 2
return sum
The above function is called in a loop which populates two lists and calls this function twice: First time with a list of len ~ 1024 items and second time with len ~ 44100 items. The loop itself can run anywhere from 100 to 100000 times depending upon the input.
For a small sized input, cProfile based profiling informs me:
ncalls tottime percall cumtime percall filename:lineno(function)
---------------------------------------------------------------------
2560 12.065 0.005 12.065 0.005 beat.py:8(sumsquared)
which is about 95% of the total running time for the script. Is there some way I can get some speed up on the function?
This is the fastest I can find