Python کو optimize کرنا اصل bottleneck تلاش کرنے کے لیے profiling سے شروع ہوتا ہے — کبھی اندازہ نہیں لگانا۔ Python کی interpreted، dynamic فطرت اسے compiled languages کی نسبت سست بناتی ہے، اس لیے optimization بہتر algorithms، C-backed libraries سے فائدہ اٹھانے، اور hot paths میں interpreter overhead کم کرنے پر مرکوز ہوتا ہے۔
پہلے profile کریں
import cProfile
cProfile.run("my_function()") # shows time spent per function call
# line-level profiling (third-party)
