[Python] Optimize what needs optimizing?
ปกติแล้ว เวลาผมเขียนโปรแกรมจะถือคตินี้มาตลอด นั่นคือ
Make it done, make it right, and then make it fast.
blog นี้จะมาบอกว่า เราจะ opimize โปรแกรมที่เขียนด้วยภาษา python ได้อย่างไรบ้าง
อย่างแรก ให้ติดตั้ง Python profiler ก่อน คลิก เพื่อดูว่าแต่ละ function ใช้เวลาในการทำงานนานเท่าไหร่
blog นี้ ผมจะสรุปจาก PerformanceTips ละกันครับ
เลือก Data structure ให้เหมาะสม
ใช้ Sorting ของ Python
อ้างอิงจาก Comparing the well-known sorting algorithm ซึ่งผมเคยเทียบประสิทธิภาพไปแล้วว่า python sorting เร็วกว่าใครเพื่อน นอกจากนั้น Guido van Rossum ยังแนะนำให้ใช้ comparator
String Concatenation
หลีกเลี่ยง (เอา string [...]
