Profiling to find bottlenecks
Key 2: Identifying application performance bottlenecks.
We should not rely on our intuition on how to optimize application. There are two major ways for logic slowdown; one is CPU time taken, and the second is the wait for results from some other entity. By profiling, we can find out such cases in which we can tweak logic, and language syntax to get better performance on the same hardware. The following code is a showtime
decorator that I use to calculate the time taken to call a function. It is simple and effective to get rapid answers:
from datetime import datetime,timedelta from functools import wraps import time def showtime(func): @wraps(func) def wrap(*args,**kwargs): st = time.time() #time clock can be used too result = func(*args,**kwargs) et = time.time() print("%s:%s"%(func.__name__,et-st)) return result return wrap @showtime def func_c(): for i in range(1000): for j in range(1000)...