Python processes a code optimization process in a text field,
First
Filter (lambda: True if keyword in. Decode ('utf8') else False, all)
It takes 18 s to run, which is too slow.
Change to view
Filter (lambda: True if keyword in. Decode ('utf8') else False, all. read (). split ('\ n '))
It's not that good. Is it that list traversal is too slow and changed to tuple?
Filter (lambda: True if keyword in. Decode ('utf8') else False ,(. Strip ()In balls ))
It is still 18 s, and the pipeline has not improved.
Now we can see the decode. Does it throw the speed? I don't think this is because the system function call is not too slow. Let's change it.
Filter (lambda: True if keyword inElse False, all. read (). decode ('utf8'). split ('\ n '))
The speed is faster, and 8 s is over. It is true that calling a function in for has a great impact on the speed.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.