python 定时执行指定的函数,python指定函数,python定时执行指定
python 定时执行指定的函数,python指定函数,python定时执行指定
python定时执行指定的函数```python
time a function using time.time() and the a @ function decorator
tested with Python24 vegaseat 21aug2005
import time
def print_timing(func): def wrapper(arg): t1 = time.time() res = func(arg) t2 = time.time() print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0) return res return wrapper
declare the @ decorator just before the function, invokes print_timing()
@print_timingdef getPrimeList(n): """ returns a list of prime numbers from 2 to < n using a sieve algorithm""" if n < 2: return [] if n == 2: return [2] # do only odd numbers starting at 3 s = range(3, n+1, 2) # n0.5 may be slightly faster than math.sqrt(n) mroot = n 0.5 half = len(s) i = 0 m = 3 while m <= mroot: if s[i]: j = (mm-3)//2 s[j] = 0 while j < half: s[j] = 0 j += m i = i+1 m = 2i+3 return [2]+[x for x in s if x]
if name == "main": print "prime numbers from 2 to <10,000,000 using a sieve algorithm" primeList = getPrimeList(10000000) time.sleep(2.5)
"""my output -->prime numbers from 2 to <10,000,000 using a sieve algorithmgetPrimeList took 4750.000 ms"""```
相关内容
- python 冒泡排序,python冒泡,[Python]代码
- python scrapy 网络采集使用代理的方法,pythonscrapy,1.在S
- 使用libvirt抓取linux kvm虚拟机的缩略图,libvirtkvm,import
- 一组python用于验证数据的函数,一组python,这是一组py
- python设置进程的环境变量,python环境变量,import ospri
- python2.7自动创建虚拟机,python2.7虚拟机,# -*- coding
- 购物,,#!/usr/bin/e
- if elif else 使用,elifelse,1 #!/usr/bin
- sys.argv经典代码,sys.argv经典,import osimp
- python编写的一个通过多线程扫描端口的代码,python多线
评论关闭