国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python定時(shí)執(zhí)行指定函數(shù)的方法

2020-02-23 01:27:19
字體:
供稿:網(wǎng)友

本文實(shí)例講述了python定時(shí)執(zhí)行指定函數(shù)的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

# time a function using time.time() and the a @ function decorator# tested with Python24  vegaseat  21aug2005import timedef 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)  # n**0.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 = (m*m-3)//2      s[j] = 0      while j < half:        s[j] = 0        j += m    i = i+1    m = 2*i+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"""

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 彭泽县| 淮安市| 荆州市| 高安市| 玉田县| 独山县| 舒兰市| 视频| 连平县| 内丘县| 太和县| 永丰县| 梁平县| 酒泉市| 巴塘县| 盈江县| 右玉县| 金堂县| 盐城市| 青岛市| 马公市| 抚松县| 宜丰县| 涪陵区| 泰顺县| 辽中县| 洛宁县| 梁山县| 荔浦县| 金堂县| 浙江省| 蒲城县| 乐业县| 萍乡市| 罗山县| 安国市| 扎囊县| 宁河县| 安国市| 曲靖市| 桐庐县|