Hello i got a problem that a function in my script takes long to execute. So i am trying to optimize the code and i am currently using cProfile and Pstats for that.
When i execute a function it takes around 0.7 seconds to 1+ seconds to finish. The item that always gives the highest duration on Windows is:
Sun Mar 10 13:55:02 2019 profiles/getColors.profile
657 function calls in 0.535 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.714 0.714 0.714 0.714 {built-in method _winapi.WaitForMultipleObjects}_winapi.WaitForMultipleObjects}
And on Linux:
2 1.013 0.506 1.013 0.506 {built-in method posix.read}
So i am going to assume it has to do something with threading but i never create any threads and my other function takes barely no time at all to complete like ~0.1 sec, So my question is why does it take so long the time to execute this code:
def getColors(image, rows, columns, sectionedPixel):
# Flooring so we do not get decimal numbers
sectionColumns = math.floor(width / columns)
sectionRows = math.floor(height / rows)
colorValues = [0, 0, 0, 0]
leftRGBVal = [0, 0, 0]
rightRGBVal = [0, 0, 0]
topRGBVal = [0, 0, 0]
botRGBVal = [0, 0, 0]
# LEFT SIDE
getRiLeSideColor(image, 0, 10, leftRGBVal)
# RIGHT SIDE
getRiLeSideColor(image, width - 10, width, rightRGBVal)
# TOP SIDE
getToBoSideColor(image, 0, 10, topRGBVal)
# BOTTOM SIDE
getToBoSideColor(image, height - 10, height, botRGBVal)
colorValues[0] = leftRGBVal
colorValues[1] = rightRGBVal
colorValues[2] = topRGBVal
colorValues[3] = botRGBVal
return colorValues
Full log of CProfile: https://pastebin.com/jAA5FkPZ
Full code: https://gist.github.com/Patrick265/592a7dccba4660a4e4210ddd5e9974eb