Increasing speed of python code

前端 未结 8 1844
野性不改
野性不改 2021-02-05 12:37

I have some python code that has many classes. I used cProfile to find that the total time to run the program is 68 seconds. I found that the following function in

8条回答
  •  野的像风
    2021-02-05 13:07

    Some curious things I noted:

    timePd is passed as a parameter but never used

    price is an array but you only ever use the last entry - why not pass the value there instead of passing the list?

    count is initialized and never used

    self.people contains multiple person objects which are then copied to either self.customers or self.noncustomers as well as having their customer flag set. Why not skip the copy operation and, on return, just iterate over the list, looking at the customer flag? This would save the expensive append.

    Alternatively, try using psyco which can speed up pure Python, sometimes considerably.

提交回复
热议问题