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


Python timeit.timeit方法代码示例

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


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

示例1: libsnmp_encode_decode

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def libsnmp_encode_decode():
    try:
        import libsnmp.rfc1905 as libsnmp_rfc1905

        def decode():
            libsnmp_rfc1905.Message().decode(ENCODED_MESSAGE)

        encode_time = float('inf')
        decode_time = timeit.timeit(decode, number=ITERATIONS)
    except ImportError:
        encode_time = float('inf')
        decode_time = float('inf')
        print('Unable to import libsnmp.')
    except SyntaxError:
        encode_time = float('inf')
        decode_time = float('inf')
        print('Syntax error in libsnmp.')

    return encode_time, decode_time 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:21,代码来源:ber.py

示例2: pyasn1_encode_decode

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def pyasn1_encode_decode():
    try:
        from pysnmp.proto import api
        from pyasn1.codec.ber import decoder

        snmp_v1 = api.protoModules[api.protoVersion1].Message()

        def decode():
            decoder.decode(ENCODED_MESSAGE, asn1Spec=snmp_v1)

        encode_time = float('inf')
        decode_time = timeit.timeit(decode, number=ITERATIONS)
    except ImportError:
        encode_time = float('inf')
        decode_time = float('inf')
        print('Unable to import pyasn1.')

    return encode_time, decode_time 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:20,代码来源:ber.py

示例3: method_compile_file

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def method_compile_file():
    print("Parsing and compiling '{}' from file... ".format(RRC_8_6_0_ASN_PATH),
          end='',
          flush=True)

    def compile_file():
        asn1tools.compile_files(RRC_8_6_0_ASN_PATH)

    time = timeit.timeit(compile_file, number=ITERATIONS)

    print('done.')

    with open(RRC_8_6_0_ASN_PATH, 'rb') as fin:
        string = fin.read()

    return round(time, 5), len(string) 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:18,代码来源:compile_methods.py

示例4: method_compile_string

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def method_compile_string():
    with open(RRC_8_6_0_ASN_PATH, 'r') as fin:
        string = fin.read()

    print("Parsing and compiling '{}'... ".format(RRC_8_6_0_ASN_PATH),
          end='',
          flush=True)

    def compile_string():
        asn1tools.compile_string(string)

    time = timeit.timeit(compile_string, number=ITERATIONS)

    print('done.')

    return round(time, 5), len(string) 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:18,代码来源:compile_methods.py

示例5: test_repeat_append_nojit

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def test_repeat_append_nojit():
    x = []
    for i in range(100000):
        x.append(i)
    return x


# print(test_repeat_append_jit())

# print(test_repeat_append_jit_foreach())
#
# for e in (test_repeat_append_jit_foreach.__func_info__.r_codeinfo.instrs):
#     print(e)
# show_instrs(test_repeat_append_jit_foreach.__func_info__.r_codeinfo.instrs)
#
# %timeit test_repeat_append_jit()
# %timeit test_repeat_append_nojit()
# %timeit test_repeat_append_jit_foreach() 
开发者ID:thautwarm,项目名称:restrain-jit,代码行数:20,代码来源:test_array_op.py

示例6: test_speed_of_reading_fcs_files

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def test_speed_of_reading_fcs_files(self):
        """Test the speed of loading a FCS files"""
        file_path = FILE_IDENTIFIER_TO_PATH['mq fcs 3.1']
        number = 1000

        time = timeit.timeit(
            lambda: parse_fcs(file_path, meta_data_only=True, reformat_meta=False), number=number)

        print('Loading fcs file {0} times with meta_data only without reformatting of '
              'meta takes {1} per loop'.format(time / number, number))

        time = timeit.timeit(
            lambda: parse_fcs(file_path, meta_data_only=True, reformat_meta=True), number=number)
        print('Loading fcs file {0} times with meta_data only with reformatting of '
              'meta takes {1} per loop'.format(time / number, number))

        time = timeit.timeit(
            lambda: parse_fcs(file_path, meta_data_only=False, reformat_meta=False), number=number)

        print('Loading fcs file {0} times both meta and data but without reformatting of '
              'meta takes {1} per loop'.format(time / number, number)) 
开发者ID:eyurtsev,项目名称:fcsparser,代码行数:23,代码来源:test_fcs_reader.py

示例7: benchmark

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def benchmark(n):
    global methods
    if '--onlyself' in sys.argv[1:]:
        methods = [ m for m in methods if m[0].startswith("tabulate") ]
    else:
        methods = methods

    results = [(desc, timeit(code, setup_code, number=n)/n * 1e6)
               for desc, code in methods]
    mintime = min(map(lambda x: x[1], results))
    results = [(desc, t, t/mintime) for desc, t in
               sorted(results, key=lambda x: x[1])]
    table = tabulate.tabulate(results,
                              [u"Table formatter", u"time, μs", u"rel. time"],
                              u"rst", floatfmt=".1f")
    print codecs.encode(table, "utf-8") 
开发者ID:gregbanks,项目名称:python-tabulate,代码行数:18,代码来源:benchmark.py

示例8: timeit

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

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

示例9: repeat

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [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

示例10: permscan

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def permscan(self, address_space, offset = 0, maxlen = None):
    times = []
    # Run a warm-up scan to ensure the file is cached as much as possible
    self.oldscan(address_space, offset, maxlen)

    perms = list(itertools.permutations(self.checks))
    for i in range(len(perms)):
        self.checks = perms[i]
        print "Running scan {0}/{1}...".format(i + 1, len(perms))
        profobj = ScanProfInstance(self.oldscan, address_space, offset, maxlen)
        value = timeit.timeit(profobj, number = self.repeats)
        times.append((value, len(list(profobj.results)), i))

    print "Scan results"
    print "{0:20} | {1:7} | {2:6} | {3}".format("Time", "Results", "Perm #", "Ordering")
    for val, l, ordering in sorted(times):
        print "{0:20} | {1:7} | {2:6} | {3}".format(val, l, ordering, perms[ordering])
    sys.exit(1) 
开发者ID:virtualrealitysystems,项目名称:aumfor,代码行数:20,代码来源:scanprof.py

示例11: test_auth_token_speed

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def test_auth_token_speed(app, client_nc):
    # To run with old algorithm you have to comment out fs_uniquifier check in UserMixin
    import timeit

    response = json_authenticate(client_nc)
    token = response.json["response"]["user"]["authentication_token"]

    def time_get():
        rp = client_nc.get(
            "/login",
            data={},
            headers={"Content-Type": "application/json", "Authentication-Token": token},
        )
        assert rp.status_code == 200

    t = timeit.timeit(time_get, number=50)
    print("Time for 50 iterations: ", t) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:19,代码来源:test_common.py

示例12: main

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def main():
    print("%s methods involved on platform %r (%s iterations, psutil %s):" % (
        len(names), sys.platform, ITERATIONS, psutil.__version__))
    for name in sorted(names):
        print("    " + name)

    # "normal" run
    elapsed1 = timeit.timeit(
        "call_normal(funs)", setup=setup, number=ITERATIONS)
    print("normal:  %.3f secs" % elapsed1)

    # "one shot" run
    elapsed2 = timeit.timeit(
        "call_oneshot(funs)", setup=setup, number=ITERATIONS)
    print("onshot:  %.3f secs" % elapsed2)

    # done
    if elapsed2 < elapsed1:
        print("speedup: +%.2fx" % (elapsed1 / elapsed2))
    elif elapsed2 > elapsed1:
        print("slowdown: -%.2fx" % (elapsed2 / elapsed1))
    else:
        print("same speed") 
开发者ID:giampaolo,项目名称:psutil,代码行数:25,代码来源:bench_oneshot.py

示例13: pytorch_baseliine

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def pytorch_baseliine(batch_size, height, width, channel, kernel_size, output_channel, stride, padding, number=100):
    # conv = torch.nn.Conv2d(channel, output_channel, (kernel_size, kernel_size), (stride, stride), (padding, padding), bias=False)
    # conv = torch.nn.functional.conv2d
    # A = torch.rand([batch_size, channel, height, width])
    # W = torch.rand([output_channel, channel, kernel_size, kernel_size])
    # # warm-up
    # conv(A, W)
    # beg = time.time()
    # for i in range(number):
    #     conv(A, W)
    # end = time.time()

    run_time = timeit.timeit(setup= 'import torch\n'
                                    'conv = torch.nn.functional.conv2d\n'
                                    'A = torch.rand([' + str(batch_size) + ', ' + str(channel) + ', ' + str(height) + ', ' + str(width) + '])\n'
                                    'W = torch.rand([' + str(output_channel) + ', ' + str(channel) + ', ' + str(kernel_size) + ', ' + str(kernel_size) + '])\n'
                                    'conv(A, W)\n',
                               stmt='conv(A, W)',
                               number=number)
    print("pytorch use {}ms".format(run_time / number * 1e3)) 
开发者ID:KnowingNothing,项目名称:FlexTensor,代码行数:22,代码来源:opt_conv_cpu.py

示例14: asn1tools_encode_decode

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def asn1tools_encode_decode():
    rrc = asn1tools.compile_files(RRC_8_6_0_ASN_PATH, 'uper')

    def encode():
        rrc.encode('BCCH-DL-SCH-Message',
                   DECODED_MESSAGE_ASN1TOOLS,
                   check_types=False)

    def decode():
        rrc.decode('BCCH-DL-SCH-Message', ENCODED_MESSAGE)

    encode_time = timeit.timeit(encode, number=ITERATIONS)
    decode_time = timeit.timeit(decode, number=ITERATIONS)

    return encode_time, decode_time 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:17,代码来源:uper.py

示例15: pycrate_encode_decode

# 需要导入模块: import timeit [as 别名]
# 或者: from timeit import timeit [as 别名]
def pycrate_encode_decode():
    try:
        import rrc_8_6_0_pycrate

        rrc = rrc_8_6_0_pycrate.EUTRA_RRC_Definitions.BCCH_DL_SCH_Message
        rrc._SAFE_INIT = False
        rrc._SAFE_VAL = False
        rrc._SAFE_BND = False
        rrc._SAFE_BNDTAB = False

        def encode():
            rrc.set_val(DECODED_MESSAGE_PYCRATE)
            rrc.to_uper()

        def decode():
            rrc.from_uper(ENCODED_MESSAGE)
            rrc()

        encode_time = timeit.timeit(encode, number=ITERATIONS)
        decode_time = timeit.timeit(decode, number=ITERATIONS)
    except ImportError:
        encode_time = float('inf')
        decode_time = float('inf')
        print('Unable to import pycrate.')
    except Exception as e:
        encode_time = float('inf')
        decode_time = float('inf')
        print('pycrate error: {}'.format(str(e)))

    return encode_time, decode_time 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:32,代码来源:uper.py


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