O'Reilly logo

Python Unlocked by Arun Tigeraniya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required