Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The example usage of time-consuming function in python

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "the example usage of time-consuming function in python". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "the example usage of time-consuming function in python".

Import stringimport randomimport timeimport functoolsdef list_from_2d_np (np_array): "" convert a 2d numpy array to a list "shape = np_array.shape total = shape [0] * shape [1] new_array = np_array.reshape (total) return list (new_array) def generate_random_str (length=20): return '.join (random.choice (string.digits + string.ascii_letters) for _ in range ( Length)) def generate_time_stamp (): time_unique_id = time.strftime ("% Y-%m-%d-%H-%M-%S" Time.localtime () return time_unique_iddef time_it (fn): @ functools.wraps (fn) def inner (* args, * * kwargs): start = time.time () fn (* args, * * kwargs) end = time.time () print ("Time cost for function `{}`: {}" .format (fn.__name__, (end-start) return inner so far I believe you have a deeper understanding of "the example usage of time-consuming functions in python", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report