当前位置: 首页>>代码示例>>Python>>正文


Python timeit.repeat方法代码示例

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


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

示例1: repeat

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def repeat(self, stmt, setup, repeat=None, number=None):
        self.fake_timer = FakeTimer()
        t = timeit.Timer(stmt=stmt, setup=setup, timer=self.fake_timer)
        kwargs = {}
        if repeat is None:
            repeat = DEFAULT_REPEAT
        else:
            kwargs['repeat'] = repeat
        if number is None:
            number = DEFAULT_NUMBER
        else:
            kwargs['number'] = number
        delta_times = t.repeat(**kwargs)
        self.assertEqual(self.fake_timer.setup_calls, repeat)
        self.assertEqual(self.fake_timer.count, repeat * number)
        self.assertEqual(delta_times, repeat * [float(number)])

    # Takes too long to run in debug build.
    #def test_repeat_default(self):
    #    self.repeat(self.fake_stmt, self.fake_setup) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_timeit.py

示例2: print_timing

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def print_timing(self):
    # pylint: disable=no-self-use
    # Test the implementation of asttokens.util.walk, which uses the same approach as
    # visit_tree(). This doesn't run as a normal unittest, but if you'd like to see timings, e.g.
    # after experimenting with the implementation, run this to see them:
    #
    #     nosetests -i print_timing -s tests.test_util
    #
    import timeit
    import textwrap
    setup = textwrap.dedent(
      '''
      import ast, asttokens
      source = "foo(bar(1 + 2), 'hello' + ', ' + 'world')"
      atok = asttokens.ASTTokens(source, parse=True)
      ''')
    print("ast", sorted(timeit.repeat(
      setup=setup, number=10000,
      stmt='len(list(ast.walk(atok.tree)))')))
    print("util", sorted(timeit.repeat(
      setup=setup, number=10000,
      stmt='len(list(asttokens.util.walk(atok.tree)))'))) 
开发者ID:gristlabs,项目名称:asttokens,代码行数:24,代码来源:test_util.py

示例3: print_timing

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def print_timing(self):
    # Print the timing of mark_tokens(). This doesn't normally run as a unittest, but if you'd like
    # to see timings, e.g. while optimizing the implementation, run this to see them:
    #
    #     nosetests -m print_timing -s tests.test_mark_tokens tests.test_astroid
    #
    # pylint: disable=no-self-use
    import timeit
    print("mark_tokens", sorted(timeit.repeat(
      setup=textwrap.dedent(
        '''
        import ast, asttokens
        source = "foo(bar(1 + 2), 'hello' + ', ' + 'world')"
        atok = asttokens.ASTTokens(source)
        tree = ast.parse(source)
        '''),
      stmt='atok.mark_tokens(tree)',
      repeat=3,
      number=1000))) 
开发者ID:gristlabs,项目名称:asttokens,代码行数:21,代码来源:test_mark_tokens.py

示例4: runTimingExperiment_calcRlogRdotv

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def runTimingExperiment_calcRlogRdotv(N=2e5, D=100, repeat=3):
  if not hasNumexpr:
    return 0
  setup = "import numpy as np; import numexpr as ne;"
  setup += "import bnpy.util.NumericUtil as N;"
  setup += "R = np.random.rand(%d, %d);" % (N, D)
  setup += "v = np.random.rand(%d)" % (N)
  elapsedTimes_np = timeit.repeat("N.calcRlogRdotv_numpy(R, v)", 
                    setup=setup, number=1, repeat=repeat)
  elapsedTimes_ne = timeit.repeat("N.calcRlogRdotv_numexpr(R, v)",
                    setup=setup, number=1, repeat=repeat)
  meanTime_np = np.mean(elapsedTimes_np)
  meanTime_ne = np.mean(elapsedTimes_ne)
  expectedGainFactor = meanTime_np / meanTime_ne
  return expectedGainFactor

########################################################### MAIN
########################################################### 
开发者ID:daeilkim,项目名称:refinery,代码行数:20,代码来源:NumericUtil.py

示例5: test_time_many_primary_many_matchup

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def test_time_many_primary_many_matchup(self):
        import logging
        import sys
        logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                            datefmt="%Y-%m-%dT%H:%M:%S", stream=sys.stdout)
        log = logging.getLogger(__name__)
        # Generate 160000 DomsPoints distributed equally in a box from -2.0 lat/lon to 2.0 lat/lon
        log.info("Generating primary points")
        x = np.arange(-2.0, 2.0, 0.01)
        y = np.arange(-2.0, 2.0, 0.01)
        primary_points = [DomsPoint(longitude=xy[0], latitude=xy[1], time=1000, depth=5.0, data_id=i) for i, xy in
                          enumerate(np.array(np.meshgrid(x, y)).T.reshape(-1, 2))]

        # Generate 2000 DomsPoints distributed randomly in a box from -2.0 lat/lon to 2.0 lat/lon
        log.info("Generating matchup points")
        matchup_points = [
            DomsPoint(longitude=random.uniform(-2.0, 2.0), latitude=random.uniform(-2.0, 2.0), time=1000, depth=5.0,
                      data_id=i) for i in xrange(0, 2000)]

        log.info("Starting matchup")
        log.info("Best of repeat(3, 2) matchups: %s seconds" % min(
            timeit.repeat(lambda: list(match_points_generator(primary_points, matchup_points, 1500)), repeat=3,
                          number=2))) 
开发者ID:apache,项目名称:incubator-sdap-nexus,代码行数:25,代码来源:Matchup_test.py

示例6: _add_stats_and_log_intermediate_steps

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def _add_stats_and_log_intermediate_steps(stats_printer,
                                          regression, 
                                          run_name,
                                          setup_function):
    if DEBUG:
        print("Running", regression.__name__, "...................")
    stats_printer.add_stats(
        run_name,
        timeit.repeat(regression, setup=setup_function, number=1,
                      repeat=CLO_TIMING_REPEATS),
        number=CLO_TIMING_NUMBER * NUM_AGRAPHS_INDVS,
        unit_mult=1000
    )
    if DEBUG:
        print(regression.__name__, "finished\n")
    _reset_iteration_count() 
开发者ID:nasa,项目名称:bingo,代码行数:18,代码来源:continous_local_opt_benchmarks.py

示例7: do_benchmarking

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def do_benchmarking():
    printer = benchmark_data.StatsPrinter("EVALUATION BENCHMARKS")
    for backend, name in [[pyBackend, "py"], [cppBackend, "c++"]]:
        agraph_module.Backend = backend
        printer.add_stats(name + ": evaluate",
                          timeit.repeat(benchmark_evaluate,
                                        number=EVAL_TIMING_NUMBER,
                                        repeat=EVAL_TIMING_REPEATS),
                          number=EVAL_TIMING_NUMBER * NUM_AGRAPHS_INDVS,
                          unit_mult=1000)
        printer.add_stats(name + ": x derivative",
                          timeit.repeat(benchmark_evaluate_w_x_derivative,
                                        number=EVAL_TIMING_NUMBER,
                                        repeat=EVAL_TIMING_REPEATS),
                          number=EVAL_TIMING_NUMBER * NUM_AGRAPHS_INDVS,
                          unit_mult=1000)
        printer.add_stats(name + ": c derivative",
                          timeit.repeat(benchmark_evaluate_w_c_derivative,
                                        number=EVAL_TIMING_NUMBER,
                                        repeat=EVAL_TIMING_REPEATS),
                          number=EVAL_TIMING_NUMBER * NUM_AGRAPHS_INDVS,
                          unit_mult=1000)
    return printer 
开发者ID:nasa,项目名称:bingo,代码行数:25,代码来源:evaluation_benchmark.py

示例8: _run_benchmarks

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def _run_benchmarks(printer, regression, regression_cpp):
    for backend, name in [[pyBackend, " py"], [cppBackend, "c++"]]:
        agraph_module.Backend = backend
        printer.add_stats(
            "py:  fitness " + name + ": evaluate ",
            timeit.repeat(regression,
                          number=FITNESS_TIMING_NUMBER,
                          repeat=FITNESS_TIMING_REPEATS),
            number=FITNESS_TIMING_NUMBER * NUM_AGRAPHS_INDVS,
            unit_mult=1000)
    printer.add_stats(
        "c++: fitness c++: evaluate ",
        timeit.repeat(regression_cpp,
                      number=FITNESS_TIMING_NUMBER,
                      repeat=FITNESS_TIMING_REPEATS),
        number=FITNESS_TIMING_NUMBER * NUM_AGRAPHS_INDVS,
        unit_mult=1000) 
开发者ID:nasa,项目名称:bingo,代码行数:19,代码来源:fitness_benchmark.py

示例9: run_benchmark

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def run_benchmark(
            benchmark_module, module, function, setup_suffix='', repeat=5, number=1000):
        setup_func = 'setup_' + function
        if setup_suffix:
            print('%s with %s:' % (function, setup_suffix), end='')
            setup_func += '_' + setup_suffix
        else:
            print('%s:' % function, end='')

        def wrapper(function, setup_func):
            function = globals()[function]
            setup_func = globals()[setup_func]
            def wrapped():
                return function(*setup_func())
            return wrapped
        results = timeit.repeat(wrapper(function, setup_func), repeat=repeat, number=number)
        print('\t%5.1fus' % (min(results) * 1000000. / number)) 
开发者ID:googlefonts,项目名称:cu2qu,代码行数:19,代码来源:cu2qu.py

示例10: run_benchmark

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def run_benchmark(
        benchmark_module, module, function, setup_suffix='', repeat=1000):
    setup_func = 'setup_' + function
    if setup_suffix:
        print('%s with %s:' % (function, setup_suffix), end='')
        setup_func += '_' + setup_suffix
    else:
        print('%s:' % function, end='')
    results = timeit.repeat(
        '%s(*args)' % function,
        setup=(SETUP_CODE % {
            'benchmark_module': benchmark_module, 'setup_function': setup_func,
            'module': module, 'function': function}),
        repeat=repeat, number=1)
    print('\tavg=%dus' % (sum(results) / len(results) * 1000000.),
          '\tmin=%dus' % (min(results) * 1000000.)) 
开发者ID:googlefonts,项目名称:cu2qu,代码行数:18,代码来源:benchmark.py

示例11: timeit

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def timeit(stmt, globals=globals()):
    import numpy as np
    import timeit as _timeit

    print("Timing '{0}'".format(stmt))
        
    # Rough approximation of a 10 runs
    trial = _timeit.timeit(stmt, globals=globals, number=10)/10
    
    # Maximum duration
    duration = 5.0
    
    # Number of repeat
    repeat = 7
    
    # Compute rounded number of trials
    number = max(1,int(10**np.ceil(np.log((duration/repeat)/trial)/np.log(10))))
    
    # Only report best run
    times = _timeit.repeat(stmt, globals=globals, number=number, repeat=repeat)
    times = np.array(times)/number
    mean = np.mean(times)
    std = np.std(times)

    # Display results
    units = {"s":  1, "ms": 1e-3, "us": 1e-6, "ns": 1e-9}
    for key,value in units.items():
        unit, factor = key, 1/value
        if mean > value: break
    mean *= factor
    std *= factor

    print("%.3g %s ± %.3g %s per loop (mean ± std. dev. of %d runs, %d loops each)" %
          (mean, unit, std, unit, repeat, number)) 
开发者ID:ASPP,项目名称:ASPP-2018-numpy,代码行数:36,代码来源:tools.py

示例12: test_repeat_zero_reps

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def test_repeat_zero_reps(self):
        self.repeat(self.fake_stmt, self.fake_setup, repeat=0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_timeit.py

示例13: test_repeat_zero_iters

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def test_repeat_zero_iters(self):
        self.repeat(self.fake_stmt, self.fake_setup, number=0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_timeit.py

示例14: test_repeat_few_reps_and_iters

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def test_repeat_few_reps_and_iters(self):
        self.repeat(self.fake_stmt, self.fake_setup, repeat=3, number=5) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_timeit.py

示例15: test_repeat_callable_stmt

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import repeat [as 别名]
def test_repeat_callable_stmt(self):
        self.repeat(self.fake_callable_stmt, self.fake_setup,
                repeat=3, number=5) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_timeit.py


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