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

Python timeit.repeat函数代码示例

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

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



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

示例1: performance

def performance(name, size, loops=100):

    libpath = os.path.join(os.getcwd(), name)
    sys.path.append(libpath)

    try:
        atm
    except NameError:
        import isa
    imp.reload(isa)

    times = []
    for element in size:
        element = int(element)
        if element == 1:
            time = repeat('atm(0.)', setup='from isa import atm',
                          number=loops, repeat=3)
        elif element > 1:
            time = repeat('atm(h)',
                          setup='from isa import atm\n'
                                'from numpy import linspace\n'
                                'h = linspace(0., 11000., {})'
                                .format(element),
                          number=loops, repeat=3)
        time = 1e3 * min(time) / loops
        times.append(time)

    sys.path.remove(libpath)

    return times
开发者ID:AeroPython,项目名称:aeropy,代码行数:30,代码来源:performance.py


示例2: time_update

def time_update(function, truncate, imsize, picture, input_im, sigma_r, sigma_s, lw, num_thread=None):

    #cython parameters
    imsize0 = imsize[0]
    imsize1 = imsize[1]
    output = picture*0.
    output5 =  np.array(output, np.float32)
    input_im5 = np.array(input_im, np.float32)

    if num_thread is None:
        times = timeit.repeat(lambda: function(sigma_s,
                                                        sigma_r,
                                                        input_im5,
                                                        imsize0,
                                                        imsize1,
                                                        output5,
                                                        lw),
                            number=3, repeat=5)
    else:
        times = timeit.repeat(lambda: function(sigma_s,
                                                    sigma_r,
                                                    input_im5,
                                                    imsize0,
                                                    imsize1,
                                                    output5,
                                                    lw,
                                                    num_thread),
                            number=3, repeat=5)
    print("{}: {}s".format(str(function) , min(times)))

    return min(times)
开发者ID:rpestourie,项目名称:filters_AVX,代码行数:31,代码来源:timefunction.py


示例3: time_big_inputs

    def time_big_inputs(self):
        n_elems_range = np.linspace(1, 2**self.max_exponent, num=self.num_test_points, dtype=int).tolist()
        times_merge = []
        times_counting = []
        sort_case= BigInputsSortCase('merge')
        for i,n_elems in enumerate(n_elems_range):
            print(i)
            sort_case.setup(n_elems=n_elems, max_elem=n_elems)
            print('max:' + str(max(sort_case.test_input)))
            elapsed_time = min(timeit.repeat(sort_case.sort, number=1, repeat=self.num_repeats))*1000
            times_merge.append(elapsed_time)
        sort_case = BigInputsSortCase('counting')
        for i, n_elems in enumerate(n_elems_range):
            print(i)
            sort_case.setup(n_elems=n_elems, max_elem=n_elems)
            elapsed_time = min(timeit.repeat(sort_case.sort, number=1, repeat=self.num_repeats))*1000
            times_counting.append(elapsed_time)

        # plot both
        plt.plot(n_elems_range, times_merge, color='red', label='Merge sort', linestyle='-', marker='o')
        plt.plot(n_elems_range, times_counting, color='blue', label='Counting sort', linestyle='-', marker='o')
        plt.title('Big Inputs case')
        plt.xlabel('size (length) of the input')
        plt.ylabel('ms.')
        plt.legend(loc='upper left', frameon=True)
        plt.show()
开发者ID:javiribera,项目名称:sorting-methods,代码行数:26,代码来源:runtime_tests.py


示例4: find_breaking_point

def find_breaking_point(f1, f2, input_generator, start=1, step=1,
                        limit=1000000, trial_count=1000, repeat_count=3):
    """
    Find size of input arguments (n0) for which f2(n0) is faster than f1(n0).
    -  f1, f2 - functions to test.
    -  input_generator - function that receives current size of input arguments and returns input data in form of tuple with first item - list of non-keyword arguments and second item - dict of keyword arguments.
    -  start - initial input data size.
    -  step - iteration step.
    -  limit - maximum size of input data.
    -  trial_count - count of executions of f1/f2 on each iteration.
    -  repeat_count - to repeat trials several times and use average performance value.

    returns n0 - size of input data for which f2(n0) is faster than f1(n0)
            or None if reaches limit.
    """
    for n in range(start, limit+1):
        curr_input = input_generator(n)
        # Test first function
        f1_results = timeit.repeat(lambda: f1(*curr_input[0], **curr_input[1]),
                                   repeat=repeat_count, number=trial_count)
        f1_avg = sum(f1_results) / len(f1_results)
        # Test second function
        f2_results = timeit.repeat(lambda: f2(*curr_input[0], **curr_input[1]), repeat=repeat_count, number=trial_count)
        f2_avg = sum(f2_results) / len(f2_results)
        # Compare performance
        if f2_avg < f1_avg:
            return n
    return None
开发者ID:dizballanze,项目名称:breaking-point,代码行数:28,代码来源:breaking_point.py


示例5: main

def main():
    '''test functions'''
    init()
    if len(argv) > 1:
        n = int(argv[1])
    else:
        print('nchess.py, usage:\nn print repeat functions')
        return
    if len(argv) > 2:
        print_sol = bool(int(argv[2]))

    functions = [perm_all, perm_op1, perm_op2, perm_op3, perm_op4, perm_op5]
    if len(argv) > 3:
        repeats = int(argv[3])
    else:
        repeats = 100
    if len(argv) > 4:
        for func in argv[4:]:
            print()
            funcstr = str(functions[int(func)]).split(' ')[1]
            print(funcstr)
            if print_sol:
                print(min(timeit.repeat('print({}({}))'.format(funcstr, n),
                                        setup='from __main__ import '+funcstr,
                                        repeat=repeats, number=1)))
            else:
                print(min(timeit.repeat('{}({})'.format(funcstr, n),
                                        setup='from __main__ import '+funcstr,
                                        repeat=repeats, number=1)))
    else:
        print(function(n) for function in functions[1:])
开发者ID:BitOfAByte,项目名称:nqueens,代码行数:31,代码来源:nchess.py


示例6: time_already_sorted

    def time_already_sorted(self):
        max_value_range = np.linspace(1, 2**self.max_exponent, num=self.num_test_points, dtype=int).tolist()
        times_diff_merge = []
        times_diff_counting = []
        for n_elems in max_value_range:
            sort_case = AlreadySortedSortCase('merge')
            sort_case.setup(n_elems=n_elems)
            elapsed_time_sorted = min(timeit.repeat(sort_case.sort, number=1, repeat=self.num_repeats))*1000
            sort_case = ManualSortCases('merge')
            sort_case.setup(np.random.permutation(n_elems).tolist())
            elapsed_time_permuted = min(timeit.repeat(sort_case.sort, number=1, repeat=self.num_repeats))*1000
            diff_merge = elapsed_time_permuted - elapsed_time_sorted
            print(diff_merge)
            times_diff_merge.append(diff_merge)
        for n_elems in max_value_range:
            sort_case = AlreadySortedSortCase('counting')
            sort_case.setup(n_elems=n_elems)
            elapsed_time_sorted = min(timeit.repeat(sort_case.sort, number=1, repeat=self.num_repeats))*1000
            sort_case = ManualSortCases('counting')
            sort_case.setup(np.random.permutation(n_elems).tolist())
            elapsed_time_permuted = min(timeit.repeat(sort_case.sort, number=1, repeat=self.num_repeats))*1000
            diff_count = elapsed_time_permuted - elapsed_time_sorted
            print(diff_count)
            times_diff_counting.append(diff_count)

        # plot both
        plt.plot(max_value_range, times_diff_merge, color='red', label='Merge sort', linestyle='-', marker='o')
        plt.plot(max_value_range, times_diff_counting, color='blue', label='Counting sort', linestyle='-', marker='o')
        plt.title('Already Sorted case')
        plt.xlabel('size (length) of the input')
        plt.ylabel(r'$RT_{PERMUTED} - RT_{SORTED}$ [ms.]')
        plt.legend(loc='upper left', frameon=True)
        plt.show()
开发者ID:javiribera,项目名称:sorting-methods,代码行数:33,代码来源:runtime_tests.py


示例7: main

def main():
    print("Calling on 10: " + str(sum_of_primes(10)))
    print("Timing new Prime Method:")
    print("Old Method")
    print(timeit.repeat("sum_of_primes(2000000)", "from __main__ import sum_of_primes", number =1))
    print("New Method")
    print(timeit.repeat("better_sum_of_primes(2000000)", "from __main__ import better_sum_of_primes", number =1))
开发者ID:JHa13y,项目名称:ProjectEuler,代码行数:7,代码来源:Problem10.py


示例8: run_case

def run_case(docs, words, word_range):
    SETUP = (
        'import random;'
        'from {module} import {func} as func;'
        'from __main__ import generate_doclist;'
        'random.seed("tidovsoctavian");'
        'docs_list = generate_doclist({docs}, {words}, {word_range})'
    )

    octavian = timeit.repeat(
            "func(docs_list)",
            setup=SETUP.format(
                module='set_similarity_octavian',
                func='similarity',
                docs=docs, words=words, word_range=word_range),
            number=NUMBER, repeat=REPEAT)
    tido = timeit.repeat(
            "func(docs_list)",
            setup=SETUP.format(
                module='set_similarity_tido',
                func='print_similar_docs',
                docs=docs, words=words, word_range=word_range),
            number=NUMBER, repeat=REPEAT)

    return {'octavian': octavian, 'tido': tido}
开发者ID:ccraciun,项目名称:setsimilarity-tido-vs-octavian,代码行数:25,代码来源:bench_similarity.py


示例9: main

def main(conf):
    """Run timed benchmark"""
    read_sequence = [1, 2, 16, 256, 512, 1024, 2048, 4096, 8192, 16384,
                     32768, 65536, 262144]
    write_sequence = [1, 2, 16, 256, 512, 1024, 2048, 4096, 8192, 16384,
                      32768, 65536, 262144]
    read_results = []
    write_results = []

    prepare_files(conf)

    for i in read_sequence:
        read_results.append((i, min(
            timeit.repeat("read_mark(%s, filehandle)" % i,
                          setup = conf['setup_read'], repeat=conf['repeat'],
                          number=conf['number']))))

    for i in write_sequence:
        write_results.append((i, min(
            timeit.repeat("write_mark(%s, filehandle, data)" % i,
                          setup = conf['setup_write'], repeat=conf['repeat'],
                          number=conf['number']))))
    out = pprint.PrettyPrinter()
    out.pprint(read_results)
    out.pprint(write_results)
开发者ID:heromod,项目名称:migrid,代码行数:25,代码来源:benchmark_raw.py


示例10: time_fit_predict

def time_fit_predict(clf, dfx, dfy, var='TF', num=10, rp=3):
    '''time fit and predict with classifier clf on training set dfx, dfy
       using num loops and rp repeats'''

#    print("time_fit_predict: var", var)
    # dfy['TF'] has two states (0, 1)
    def fit_clf():
        do_fit(clf, dfx, dfy['TF'])
    
    # should run predict on test not train data
    def predict_clf():
        do_predict(clf, dfx, dfy['TF'])
    
    # dfy['Y'] has six states (1-6)
    def fit_clf_multi():
        do_fit(clf, dfx, dfy['Y'])
    
    def predict_clf_multi():
        do_predict(clf, dfx, dfy['Y'])
    
    if var=='Y':
        tfit  = min(timeit.repeat(fit_clf_multi, repeat=rp, number=num))
        tpred = min(timeit.repeat(predict_clf_multi, repeat=rp, number=num))
    else:
        tfit  = min(timeit.repeat(fit_clf, repeat=rp, number=num))
        tpred = min(timeit.repeat(predict_clf, repeat=rp, number=num))
    tfit = tfit * 1e3 / num
    tpred = tpred * 1e3 / num

    return tfit, tpred
开发者ID:bfetler,项目名称:sklearn_clf_speed,代码行数:30,代码来源:speed_test.py


示例11: _measure_performance

def _measure_performance():
    import timeit

    _sqdiff_numba = _make_sqdiff_numba()

    print "All times in ms                         numpy\tnumba"
    print "type    \tnumpy\tnumba\tC\tspeedup\tspeedup\tsize\talignment"
    for _ in range(100):
        frame_cropped, template, template_transparent = _random_template()

        for l, t in [("template ", template),
                     ("with mask", template_transparent),
                     ("unmasked ", template_transparent[:, :, :3])]:
            # pylint: disable=cell-var-from-loop

            np_time = min(timeit.repeat(
                lambda: _sqdiff_numpy(t, frame_cropped),
                repeat=3, number=10)) / 10
            c_time = min(timeit.repeat(
                lambda: _sqdiff_c(t, frame_cropped),
                repeat=3, number=10)) / 10
            if _sqdiff_numba:
                numba_time = min(timeit.repeat(
                    lambda: _sqdiff_numba(t, frame_cropped),
                    repeat=3, number=10)) / 10
            else:
                numba_time = float('nan')
            print "%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%i x %i \t%s" % (
                l, np_time * 1000, numba_time * 1000, c_time * 1000,
                np_time / c_time, numba_time / c_time,
                frame_cropped.shape[1], frame_cropped.shape[0],
                frame_cropped.ctypes.data % 8)
开发者ID:stb-tester,项目名称:stb-tester,代码行数:32,代码来源:sqdiff.py


示例12: do_it

def do_it(cmd, data_str, num_threads, globals, number, repeat, divisor):
    if num_threads == 1:
        times = timeit.repeat('%s(%s, core)' % (cmd, data_str), globals=globals, number=number, repeat=repeat)
    else:
        times = timeit.repeat('_run_x(%s, %s, %s, core=core)' % (cmd, data_str, num_threads), globals=globals,
                              number=number, repeat=repeat)
    print_time(cmd, times, divisor)
开发者ID:vivisect,项目名称:synapse,代码行数:7,代码来源:benchmark_cortex.py


示例13: measuringExecutionTimes

 def measuringExecutionTimes(self):
     print "---- measuringExecutionTimes() ----"
     def f(x):
         return x * x
     import timeit
     print timeit.repeat("for x in range(100): lambda x: x*10","",
               number=100000)
开发者ID:DominikStyp,项目名称:Python-language-issues,代码行数:7,代码来源:LoopTypes.py


示例14: main

def main():
    for m in maps:
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                tcod.map_set_properties(m, x, y, True, True)

    for thread in threads:
        thread.start()

    print('Python %s\n%s\n%s' % (sys.version, platform.platform(),
                                   platform.processor()))

    print('\nComputing field-of-view for %i empty %ix%i maps.' %
          (len(maps), MAP_WIDTH, MAP_HEIGHT))
    single_time = min(timeit.repeat(test_fov_single, number=1))
    print('1 thread: %.2fms' % (single_time * 1000))

    multi_time = min(timeit.repeat(test_fov_threads, number=1))
    print('%i threads: %.2fms' % (THREADS, multi_time * 1000))
    print('%.2f%% efficiency' %
          (single_time / (multi_time * THREADS) * 100))

    print('\nComputing AStar from corner to corner %i times on seperate empty'
          ' %ix%i maps.' % (PATH_NUMBER, MAP_WIDTH, MAP_HEIGHT))
    single_time = min(timeit.repeat(test_astar_single, number=1))
    print('1 thread: %.2fms' % (single_time * 1000))

    multi_time = min(timeit.repeat(test_astar_threads, number=1))
    print('%i threads: %.2fms' % (THREADS, multi_time * 1000))
    print('%.2f%% efficiency' %
          (single_time / (multi_time * THREADS) * 100))
开发者ID:HexDecimal,项目名称:libtcod-cffi,代码行数:31,代码来源:thread_jobs.py


示例15: test_performance

    def test_performance(self):
        call, args = self.get_callable(*self.django_filter_args())
        df_time = min(repeat(
            lambda: call(*args),
            number=self.iterations,
            repeat=self.repeat,
        ))

        call, args = self.get_callable(*self.rest_framework_filters_args())
        drf_time = min(repeat(
            lambda: call(*args),
            number=self.iterations,
            repeat=self.repeat,
        ))

        diff = (drf_time - df_time) / df_time * 100.0

        if verbosity >= 2:
            print('\n' + '-' * 32)
            print('%s performance' % self.label)
            print('django-filter time:\t%.4fs' % df_time)
            print('drf-filters time:\t%.4fs' % drf_time)
            print('performance diff:\t%+.2f%% ' % diff)
            print('-' * 32)

        self.assertTrue(drf_time < (df_time * self.threshold))
开发者ID:edmorley,项目名称:django-rest-framework-filters,代码行数:26,代码来源:tests.py


示例16: run_profile

def run_profile():
    print 'oh yeah'
    setup='''
from whiskeynode import WhiskeyNode
from whiskeynode import whiskeycache
from whiskeynode.db import db

default_sort = [('_id', -1)]

class Node(WhiskeyNode):
    COLLECTION_NAME = 'test_node'
    COLLECTION = db[COLLECTION_NAME]
    FIELDS = {
        'myVar':int,
    }
    def __init__(self, *args, **kwargs):
        WhiskeyNode.__init__(self, *args, **kwargs)
nodes = [Node({'myVar':i}) for i in range(10000)]
'''

    query='''
whiskeycache.find(Node, {"myVar":{"$gt":500}}, default_sort)
    '''

    N = 1
    R = 3
    print timeit.repeat(query, setup=setup, repeat=R, number=N)
开发者ID:jeffreybrowning,项目名称:whiskeynode,代码行数:27,代码来源:profile.py


示例17: plot_case

def plot_case(n_floats=10, n_ints=0, n_strs=0, float_format=None, str_val=None):
    global table1, output_text
    n_rows = (10000, 20000, 50000, 100000, 200000)  # include 200000 for publish run
    numbers = (1,     1,     1,       1,      1)
    repeats = (3,     2,     1,       1,      1)
    times_fast = []
    times_fast_parallel = []
    times_pandas = []
    for n_row, number, repeat in zip(n_rows, numbers, repeats):
        table1 = NamedTemporaryFile()
        make_table(table1, n_row, n_floats, n_ints, n_strs, float_format, str_val)
        t = timeit.repeat("ascii.read(table1.name, format='basic', guess=False, use_fast_converter=True)", 
                   setup='from __main__ import ascii, table1', number=number, repeat=repeat)
        times_fast.append(min(t) / number)
        t = timeit.repeat("ascii.read(table1.name, format='basic', guess=False, parallel=True, use_fast_converter=True)", 
                   setup='from __main__ import ascii, table1', number=number, repeat=repeat)
        times_fast_parallel.append(min(t) / number)
        t = timeit.repeat("pandas.read_csv(table1.name, sep=' ', header=0)", 
                   setup='from __main__ import table1, pandas', number=number, repeat=repeat)
        times_pandas.append(min(t) / number)
    plt.loglog(n_rows, times_fast, '-or', label='io.ascii Fast-c')
    plt.loglog(n_rows, times_fast_parallel, '-og', label='io.ascii Parallel Fast-c')
    plt.loglog(n_rows, times_pandas, '-oc', label='Pandas')
    plt.grid()
    plt.legend(loc='best')
    plt.title('n_floats={} n_ints={} n_strs={} float_format={} str_val={}'.format(
                            n_floats, n_ints, n_strs, float_format, str_val))
    plt.xlabel('Number of rows')
    plt.ylabel('Time (sec)')
    img_file = 'graph{}.png'.format(len(output_text) + 1)
    plt.savefig(img_file)
    plt.clf()
    text = 'Pandas to io.ascii Fast-C speed ratio: {:.2f} : 1<br/>'.format(times_fast[-1] / times_pandas[-1])
    text += 'io.ascii parallel to Pandas speed ratio: {:.2f} : 1'.format(times_pandas[-1] / times_fast_parallel[-1])
    output_text.append((img_file, text))
开发者ID:mdmueller,项目名称:ascii-profiling,代码行数:35,代码来源:parallel.py


示例18: reverseString3

def reverseString3(originalString):
    print min(timeit.repeat("''.join(reversed('world'))"))
# 2.2613844704083021
    print min(timeit.repeat("'world'[::-1]"))
# 0.28049658041891234
    print min(timeit.repeat("start=stop=None; step=-1; 'world'[start:stop:step]"))
# 0.37622163503510819
    print min(timeit.repeat("start=stop=None; step=-1; reverse_slice = slice(start, stop, step); 'world'[reverse_slice]"))
开发者ID:Saiven22,项目名称:python-basics,代码行数:8,代码来源:ReverseTest.py


示例19: warm_up

def warm_up():
    log.info('Warming up the Pypy JIT compiler...')
    timeit.repeat(
        stmt=protobuf,
        setup=protobuf_setup,
        repeat=3,
        number=10**4,
    )
开发者ID:thelinuxkid,项目名称:python-protolite,代码行数:8,代码来源:benchmark.py


示例20: main

def main():

    #print("Timing bruteforce  Method:")
    #print(timeit.repeat("superNaive()", "from __main__ import superNaive", number=1))
    print("timing smarterNaive Method:")
    print(timeit.repeat("smarterNaive()", "from __main__ import smarterNaive", number=1))
    print("timing number Theory Method:")
    print(timeit.repeat("smartest()", "from __main__ import smartest", number=1))
开发者ID:JHa13y,项目名称:ProjectEuler,代码行数:8,代码来源:Problem12.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python timeit.time函数代码示例发布时间:2022-05-27
下一篇:
Python timeit.reindent函数代码示例发布时间: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