Python processes a code optimization process in a text field,

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.