Python exercises a record function to run the adorner

Source: Internet
Author: User
Tags local time

1. Write an adorner to see when the function executes


Import datetime
Import time
def jishi (fun):
Def warper ():
Start_time = Datetime.datetime.now ()
Fun ()
End_time = Datetime.datetime.now ()
Haoshi = (end_time-start_time). Total_seconds ()
Print ("function run time {}". Format (Haoshi))
Return Warper ()

@jishi
Def Yunsuan ():
Time.sleep (2)
For x in range (100):
Print (x)
Yunsuan ()


Summary: The general idea is to use local time after the function is run minus the local time before the function is run. about why the adorner is nested in a double function, because the adorner is meant to be the code and invocation of the original function, so it requires warper to be encapsulated together with the original function and the added functionality.

return together.

Python exercises a record function to run the adorner

Related Article

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.