Skip to content
KerwinKoo edited this page Dec 26, 2015 · 1 revision

python 提高效率

list for循环优化

要避免:

s = ""
for x in list: 
   s += func(x)

要使用:

slist = [func(elt) for elt in somelist] 
s = "".join(slist)

python 使用profile进行性能分析

import profile 
def profileTest(): 
   Total =1; 
   for i in range(10): 
       Total=Total*(i+1) 
       print Total 
   return Total 
if __name__ == "__main__": 
   profile.run("profileTest()")  #使用profile

[[TOC]]

Clone this wiki locally