• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python time.timer函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中time.timer函数的典型用法代码示例。如果您正苦于以下问题:Python timer函数的具体用法?Python timer怎么用?Python timer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了timer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: simulator

def simulator():
    res_slow = []
    res_fast = []

    clusters = []
    for size in range(2, 201):
        clusters.append(gen_random_clusters(size))

    # slow
    for clist in clusters:
        slow_start = timer()
        slow(clist)
        slow_end = timer()
        res_slow.append(slow_end - slow_start)

    # fast
    for clist in clusters:
        fast_start = timer()
        fast(clist)
        fast_end = timer()
        res_fast.append(fast_end - fast_start)


    x_axis = [num for num in range(2, 201)]
    plt.title('Comparison of efficiency in desktop python environment')
    plt.xlabel('size of random clusters')
    plt.ylabel('running time (seconds)')
    plt.plot(x_axis, res_slow, '-b', label='slow_closest_pair', linewidth=2)
    plt.plot(x_axis, res_fast, '-r', label='fast_closest_pair', linewidth=2)
    plt.legend(loc='upper left')
    plt.show()
开发者ID:HamidehIraj,项目名称:algorithmic-thinking,代码行数:31,代码来源:moduleSix.py


示例2: trycontext

def trycontext(n=100000):
    while True:
        from time import perf_counter as timer

        i = iter(range(n))
        t1 = timer()
        while True:
            try:
                next(i)
            except StopIteration:
                break
        t2 = timer()
        # print("small try", t2 - t1)
        i = iter(range(n))
        t3 = timer()
        try:
            while True:
                next(i)
        except StopIteration:
            pass
        t4 = timer()

        tsmall = D(t2) - D(t1)
        tbig = D(t4) - D(t3)

        fastest = "Small Try" if tsmall < tbig else "Big Try"

        # noinspection PyStringFormat
        print("small try %.8f" % tsmall, "big try %.8f" % tbig, "fastest:", fastest,
              "%%%.1f" % ((tsmall - tbig) / tsmall * 100))
开发者ID:nitetrain8,项目名称:scripts,代码行数:30,代码来源:old_cli.py


示例3: main

def main():
    start = timer()
    # Calling dork_scanner from makman.py for 15 pages and 4 parallel processes
    search_result = dork_scanner('intext:Developed by : iNET inurl:photogallery.php', '15', '4')
    file_string = '######## By MakMan ########\n'
    final_result = []
    count = 0
    # Running 8 parallel processes for the exploitation
    with Pool(8) as p:
        final_result.extend(p.map(inject, search_result))
    for i in final_result:
        if not 'Not Vulnerable' in i and not 'Bad Response' in i:
            count += 1
            print('------------------------------------------------\n')
            print('Url     : http:' + i.split(':')[1])
            print('User    : ' + i.split(':')[2])
            print('Version : ' + i.split(':')[3])
            print('------------------------------------------------\n')
            file_string = file_string + 'http:' + i.split(':')[1] + '\n' + i.split(':')[2] + '\n' + i.split(':')[3] + '\n\n\n'
    # Writing vulnerable URLs in a file makman.txt
    with open('makman.txt', 'a', encoding='utf-8') as file:
        file.write(file_string)
    print('Total URLs Scanned    : %s' % len(search_result))
    print('Vulnerable URLs Found : %s' % count)
    print('Script Execution Time : %s' % (timer() - start,))
开发者ID:dockerized89,项目名称:hyper,代码行数:25,代码来源:main.py


示例4: main

def main():

    # ********************************************************************
    # read and test input parameters
    # ********************************************************************

    print('Parallel Research Kernels version ') #, PRKVERSION
    print('Python Dense matrix-matrix multiplication: C = A x B')

    if len(sys.argv) != 3:
        print('argument count = ', len(sys.argv))
        sys.exit("Usage: ./transpose <# iterations> <matrix order>")

    iterations = int(sys.argv[1])
    if iterations < 1:
        sys.exit("ERROR: iterations must be >= 1")

    order = int(sys.argv[2])
    if order < 1:
        sys.exit("ERROR: order must be >= 1")

    print('Number of iterations = ', iterations)
    print('Matrix order         = ', order)

    # ********************************************************************
    # ** Allocate space for the input and transpose matrix
    # ********************************************************************

    A = numpy.fromfunction(lambda i,j: j, (order,order), dtype=float)
    B = numpy.fromfunction(lambda i,j: j, (order,order), dtype=float)
    C = numpy.zeros((order,order))

    for k in range(0,iterations+1):

        if k<1: t0 = timer()

        #C += numpy.matmul(A,B) # requires Numpy 1.10 or later
        C += numpy.dot(A,B)

    t1 = timer()
    dgemm_time = t1 - t0

    # ********************************************************************
    # ** Analyze and output results.
    # ********************************************************************

    checksum = numpy.linalg.norm(numpy.reshape(C,order*order),ord=1)

    ref_checksum = 0.25*order*order*order*(order-1.0)*(order-1.0)
    ref_checksum *= (iterations+1)

    epsilon=1.e-8
    if abs((checksum - ref_checksum)/ref_checksum) < epsilon:
        print('Solution validates')
        avgtime = dgemm_time/iterations
        nflops = 2.0*order*order*order
        print('Rate (MF/s): ',1.e-6*nflops/avgtime, ' Avg time (s): ', avgtime)
    else:
        print('ERROR: Checksum = ', checksum,', Reference checksum = ', ref_checksum,'\n')
        sys.exit("ERROR: solution did not validate")
开发者ID:ParRes,项目名称:Kernels,代码行数:60,代码来源:dgemm-numpy.py


示例5: main

def main():
    print (Style.BRIGHT)
    banner()
    count        = 0
    start        = timer()
    file_string  = ''
    final_result = []
    # Make sure urls.txt is in the same directory
    try:
        with open( 'urls.txt' ) as f:
            search_result = f.read().splitlines()
    except:
        print( 'urls.txt not found in the current directory. Create your own or download from here. http://makman.tk/vb/urls.txt\n' )
        sys.exit(0)
    search_result = list( set( search_result ) )
    print (' [+] Executing Exploit for ' + Fore.RED + str( len( search_result ) ) + Fore.WHITE + ' Urls.\n')
    with Pool(8) as p:
        final_result.extend( p.map( inject, search_result ) )
    for i in final_result:
        if not 'Not Vulnerable' in i and not 'Bad Response' in i:
            count += 1
            file_string = file_string + i.split( ':::' )[0].strip() + '\n' + i.split( ':::' )[1].strip() + '\n' + i.split( ':::' )[2].strip() + '\n' + i.split( ':::' )[3].strip()
            file_string = file_string + '\n------------------------------------------\n'
    # Writing Result in a file makman.txt
    with open( 'makman.txt', 'a', encoding = 'utf-8' ) as rfile:
        rfile.write( file_string )
    print( 'Total URLs Scanned    : ' + str( len( search_result ) ) )
    print( 'Vulnerable URLs Found : ' + str( count ) )
    print( 'Script Execution Time : ' + str ( timer() - start ) + ' seconds' )
开发者ID:rummykhan,项目名称:vBulletin-5.1.x-PreAuth-RCE,代码行数:29,代码来源:vBulletin-5.0.x-PreAuth-RCE.py


示例6: main

def main():
    banner()
    start         = timer()
    dork          = 'inurl:"/component/tags/"'
    file_string   = '######## By MakMan ########\n'
    final_result  = []
    count         = 0
    print( '[+] Starting dork scanner for : ' + dork)
    sys.stdout.flush()
    #Calling dork_scanner from makman.py for 6 pages and 6 parallel processes
    search_result = dork_scanner( dork, '6', '6' )
    print( '[+] Total URLs found : ' + str( len( search_result ) ) )
    with open( 'urls.txt', 'a', encoding = 'utf-8' ) as ufile:
        ufile.write( '\n'.join( search_result ) )
    print( '[+] URLs written to urls.txt' )
    print( '\n[+] Trying Joomla SQL Injection exploit on ' + str( len( search_result ) ) + ' urls' )
    sys.stdout.flush()
    #Running 8 parallel processes for the exploitation
    with Pool(8) as p:
        final_result.extend( p.map( inject, search_result ) )
    for i in final_result:
        if not 'Not Vulnerable' in i and not 'Bad Response' in i:
            count += 1
            file_string = file_string + i.split('~:')[0] + '\n' + i.split('~:')[1] + '\n' + i.split('~:')[2] + '\n' + i.split('~:')[3] + '\n' + i.split('~:')[4] + '\n' + i.split('~:')[5] + '\n' + i.split('~:')[6] + '\n\n\n'
    #Writing vulnerable URLs in a file makman.txt
    with open( 'makman.txt', 'a', encoding = 'utf-8' ) as rfile:
        rfile.write( file_string )
    print( 'Total URLs Scanned    : ' + str( len( search_result ) ) )
    print( 'Vulnerable URLs Found : ' + str( count ) )
    print( 'Script Execution Time : ' + str ( timer() - start ) + ' seconds' )
开发者ID:cinno,项目名称:joomla-sqli-mass-exploit,代码行数:30,代码来源:joomla_sqli_mass_exploit.py


示例7: test_map

def test_map(times, mock=quick_strptime, repeat=repeat):
    t1 = timer()
    stripped = map(str.strip, times)
    raw = list(takewhile(bool, stripped))
    fmt = ParseDateFormat(raw[0])
    list(map(mock, raw, repeat(fmt)))
    t2 = timer()
    return t2 - t1
开发者ID:nitetrain8,项目名称:pbslib,代码行数:8,代码来源:open_data_report.py


示例8: do_parse_test

def do_parse_test(times, func=quick_strptime):
    t1 = timer()
    stripped = map(str.strip, times)
    raw = list(takewhile(bool, stripped))
    fmt = ParseDateFormat(raw[0])
    list(func(date, fmt) for date in raw)
    t2 = timer()
    return t2 - t1
开发者ID:nitetrain8,项目名称:pbslib,代码行数:8,代码来源:open_data_report.py


示例9: _get_fps

def _get_fps(self, frame):
    elapsed = int()
    start = timer()
    preprocessed = self.framework.preprocess(frame)
    feed_dict = {self.inp: [preprocessed]}
    net_out = self.sess.run(self.out, feed_dict)[0]
    processed = self.framework.postprocess(net_out, frame, False)
    return timer() - start
开发者ID:V-Italy,项目名称:YOLO_Object_Detection,代码行数:8,代码来源:help.py


示例10: time_test

 def time_test(container, key_count, key_range, randrange=randrange, timer=timer):
     t1 = timer()
     for _i in range(key_count):
         keys = test_key % randrange(key_range)
         container[keys]
     t2 = timer()
     
     return t2 - t1
开发者ID:nitetrain8,项目名称:pbslib,代码行数:8,代码来源:cachetypes.py


示例11: test

def test( *args ):
    start = timer()
    result = [ url for url in sitemap( *args )]
    elapsed = timer() - start
    print( 'Result: ', end ='' )
    for r in result:
        print( GET_DUMMY. search( r ). group(), end= ' ' )
    print()
    print( 'Elapsed:', elapsed * 1000, 'miliseconds' )
开发者ID:avnr,项目名称:pametis,代码行数:9,代码来源:test.py


示例12: do_superfast_test

def do_superfast_test(times, special_map=special_handler_map):
    t1 = timer()
    stripped = map(str.strip, times)
    raw = list(takewhile(bool, stripped))
    fmt = ParseDateFormat(raw[0])
    func = special_map[fmt]
    list(map(func, raw))
    t2 = timer()
    return t2 - t1
开发者ID:nitetrain8,项目名称:pbslib,代码行数:9,代码来源:open_data_report.py


示例13: main

def main(argv):
    # Read Config
    starttime = timer()
    iniFile = "input/halo_makeDerivs.ini"
    Config = ConfigParser.SafeConfigParser()
    Config.optionxform = str
    Config.read(iniFile)
    paramList = []
    fparams = {}
    cosmo = {}
    stepSizes = {}
    fparams['hmf_model'] = Config.get('general','hmf_model')
    fparams['exp_name'] = Config.get('general','exp_name')
    for (key, val) in Config.items('hmf'):
        if ',' in val:
            param, step = val.split(',')
            paramList.append(key)
            fparams[key] = float(param)
            stepSizes[key] = float(step)
        else:
            fparams[key] = float(val)
    # Make a separate list for cosmology to add to massfunction
    for (key, val) in Config.items('cosmo'):
        if ',' in val:
            param, step = val.split(',')
            paramList.append(key)
            cosmo[key] = float(param)
            stepSizes[key] = float(step)
        else:
            cosmo[key] = float(val)
    fparams['cosmo'] = cosmo

    for paramName in paramList:
        #Make range for each parameter
        #First test: x2 the range, x0.01 the stepsize
        if paramName in cosmo:
            start = fparams['cosmo'][paramName] - stepSizes[paramName]
            end   = fparams['cosmo'][paramName] + stepSizes[paramName]
        else:
            start = fparams[paramName] - stepSizes[paramName]
            end   = fparams[paramName] + stepSizes[paramName]
        width = stepSizes[paramName]*0.01
        paramRange = np.arange(start,end+width,width)
        for paramVal in paramRange: 
            if paramName in cosmo:
                params = fparams.copy()
                params['cosmo'][paramName] = paramVal
            else:
                params = fparams.copy()
                params[paramName] = paramVal
            print paramName,paramVal
            N = clusterNum(params)
            np.savetxt("output/step/"+fparams['exp_name']+'_'+fparams['hmf_model']+"_"+paramName+"_"+str(paramVal)+".csv",N,delimiter=",")

        #----------------------------
        endtime = timer()
        print "Time elapsed: ",endtime-starttime
开发者ID:NamHoNguyen,项目名称:ClustersForecast,代码行数:57,代码来源:halo_step.py


示例14: timing_middleware

def timing_middleware(next, root, info, **args):
    start = timer()
    return_value = next(root, info, **args)
    duration = timer() - start
    logger.debug("{parent_type}.{field_name}: {duration} ms".format(
        parent_type=root._meta.name if root and hasattr(root, '_meta') else '',
        field_name=info.field_name,
        duration=round(duration * 1000, 2)
    ))
    return return_value
开发者ID:marcosptf,项目名称:fedora,代码行数:10,代码来源:middleware.py


示例15: run

def run(cmd, timeout_sec):
    start = timer()
    with Popen(cmd, shell=True, stdout=PIPE, preexec_fn=os.setsid) as process:
        try:
            output = process.communicate(timeout=timeout_sec)[0]
        except TimeoutExpired:
            os.killpg(process.pid, signal.SIGINT) # send signal to the process group
            output = process.communicate()[0]
            print("DEBUG: process timed out: "+cmd)
    print('DEBUG: Elapsed seconds: {:.2f}'.format(timer() - start))
开发者ID:mehstruslehpy,项目名称:Documents,代码行数:10,代码来源:exprweb.py


示例16: search

def search(identity, num_of_imgs):
    
    start = timer()
    
    #inizialize the queue for multithreading
    queue = Queue.Queue(maxsize=0)
    
    #create query
    query = identity['name'].replace('_', ' ')
    query = query.split()
    query = '+'.join(query)
    
    #build a dictionary with search info
    data = {
            'query': query,
            'label': identity['label'],
            'num_of_imgs': num_of_imgs,
            'header': {'User-Agent': 'Mozilla/5.0'} 
    }
    
    #start threads
    threads = []
    if use_bing == 'true':
        
        bing_search = Thread(target=fetcher, args=(queue, 'bing', data))
        threads.append(bing_search)
        
    if use_aol == 'true':
        
        aol_search_1 = Thread(target=fetcher, args=(queue, 'aol1', data))
        aol_search_2 = Thread(target=fetcher, args=(queue, 'aol2', data))
        threads.append(aol_search_1)
        threads.append(aol_search_2)
        
    if use_yahoo == 'true':
        
        yahoo_search = Thread(target=fetcher, args=(queue, 'yahoo', data))
        threads.append(yahoo_search)
    
    
    for t in threads:
        t.start()
    
    for t in threads:
        t.join()
    
    #if queue is not empty, save urls to db (status = OK), else end script (STATUS = ERR_F)
    if not queue.empty():
        queue_size = queue.qsize()
        insert_urls(queue, identity, queue_size)
        print 'Collector terminated for identity: ' + identity['name'] + ' - Number of images: ' \
            + str(queue_size) + ' - Elapsed time: ' + str((timer() - start))
    else:
        update_identity_status(identity, 'ERR_F')
        print 'Collector terminated for identity: ' + identity['name'] + ' - Elapsed time: ' + str((timer() - start))     
开发者ID:smeucci,项目名称:dbmm,代码行数:55,代码来源:collector.py


示例17: benchmark

def benchmark(client, fn, num_transactions=200, num_workers=10, *args, **kwargs):
    start = timer()
    total_latency = 0

    with concurrent.futures.ThreadPoolExecutor(max_workers=num_workers) as executor:
        futures = [executor.submit(time_transaction(fn), client, *args, **kwargs) for _ in range(num_transactions)]

        latencies = [f.result() for f in concurrent.futures.as_completed(futures)]

        total_throughput = num_transactions / (timer() - start)

        return (latencies, total_throughput)
开发者ID:jaredp,项目名称:ReadTransactionalKVS,代码行数:12,代码来源:benchmark.py


示例18: inplace_speed

def inplace_speed():
    from time import perf_counter as timer
    _map = map
    n = D(1)
    i = D(1)
    incr = i.__add__

    loops = 100000 * 100

    test_data = tuple(D(1) for _ in range(loops))

    t1 = timer()
    for n in test_data:
        n = incr(n)
    t2 = timer()

    t3 = timer()
    for n in test_data:
        n += i
    t4 = timer()

    t5 = timer()
    for num in _map(incr, test_data):
        a = num
    t6 = timer()

    t7 = timer()
    for num in test_data:
        a = num + i

    t8 = timer()

    print("Incr:", t2 - t1, "normal:", t4 - t3, 'map:', t6 - t5, "comp", t8 - t7)
开发者ID:nitetrain8,项目名称:scripts,代码行数:33,代码来源:old_cli.py


示例19: get_result

def get_result(worker_name, uuid, timeout=None, sg_url=SG_URL):
    """
    Wait for processing results and return RAW data structure.

    :param timeout: How many seconds to wait for a result.
    :param worker_name: name of the worker
    :param uuid: UUID of the task
    :param sg_url: URL of the service gateway
    """
    logger = getLogger(__name__)
    status = None
    logger.info("Getting result of processing request %s for %s",
                uuid, worker_name)
    status_url = urljoin(sg_url, "{}/status".format(worker_name))
    logger.debug("Status URL is %s", status_url)
    starttime = timer()
    logger.debug("Started at %s", starttime)
    if timeout:
        timeout = int(timeout)
        logger.info("Using %s as timeout value", timeout)
    while status != 'SUCCESS':
        logger.info("Waiting for success state")
        sleep(SUCCESS_WAIT_ITER_TIME)
        r_val = requests.get(status_url, params={'uuid': uuid})
        if r_val.status_code != 502:  # Ignore Bad gateway return codes...
            r_val.raise_for_status()
        else:
            logger.warning("BAD gateway response: %s", r_val)
        status = r_val.json()['status']
        logger.debug(r_val.text)
        logger.info("Status is %s", status)
        if status == "FAILURE":
            raise ServerError("Error: Remote server says: {}".
                              format(r_val.json()['result']['message']))
        elif status == "PROGRESS":
            progress = r_val.json()['result']['current']
            logger.info("Progress stated at %s%%", progress)
        elif status in ['EXPIRED', 'REVOKED']:
            raise ServerError("Error with task status: Contact administrator")

        latency = int(timer() - starttime)
        logger.info("Current latency is %s", latency)
        if latency > timeout:
            raise TimeOutError("Process did not succeed in required time")

    status_result = r_val.json()
    logger.debug("Result string is %s", status_result)
    return status_result
开发者ID:crim-ca,项目名称:RESTPackage,代码行数:48,代码来源:run_process.py


示例20: main

def main():
    start = timer()
    # Empty List to store the Urls
    result = []
    arguments = docopt(__doc__, version='Google scraper')
    search = arguments['<search>']
    pages = arguments['<pages>']
    # Calling the function [pages] times.
    for page in range(0, int(pages)):
        # Getting the URLs in the list
        result.extend(get_urls(search, str(page * 10)))
    # Removing Duplicate URLs
    result = list(set(result))
    print(*result, sep='\n')
    print('\nTotal URLs Scraped : %s ' % str(len(result)))
    print('Script Execution Time : %s ' % (timer() - start,))
开发者ID:dockerized89,项目名称:hyper,代码行数:16,代码来源:web_scraper.py



注:本文中的time.timer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python time.timestamp函数代码示例发布时间:2022-05-27
下一篇:
Python time.time函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap