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


Python Timer.print_exc方法代码示例

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


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

示例1: main

# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import print_exc [as 别名]
def main():
    t = Timer( 'euler14()', "from __main__ import euler14" )

    try:
        print t.timeit( 1 )
    except:
        print t.print_exc()
开发者ID:JeroenDeDauw,项目名称:ProjectEuler,代码行数:9,代码来源:p14.py

示例2: time_query_using_module

# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import print_exc [as 别名]
def time_query_using_module(module):
    # This is largely copied verbatim from the 'timeit' module
    repeat = 3
    number = 10
    verbose = True
    precision = 3
    stmt = partial(query_using_greenlets, module)
    t = Timer(stmt)
    try:
        r = t.repeat(repeat, number)
    except:
        t.print_exc()
        return 1
    best = min(r)
    if verbose:
        print("raw times:", " ".join(["%.*g" % (precision, x) for x in r]))
    print("%s: %d loops," % (module.__name__, number))
    usec = best * 1e6 / number
    if usec < 1000:
        print("best of %d: %.*g usec per loop" % (repeat, precision, usec))
    else:
        msec = usec / 1000
        if msec < 1000:
            print("best of %d: %.*g msec per loop" % (repeat, precision, msec))
        else:
            sec = msec / 1000
            print("best of %d: %.*g sec per loop" % (repeat, precision, sec))
开发者ID:gilesbrown,项目名称:gsqlite3,代码行数:29,代码来源:demo.py

示例3: time_stmt

# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import print_exc [as 别名]
def time_stmt(stmt='pass', setup='pass', number=0, repeat=3):
    """Timer function with the same behaviour as running `python -m timeit `
    in the command line.

    :return: elapsed time in seconds or NaN if the command failed.
    :rtype: float
    """

    t = Timer(stmt, setup)

    if not number:
        # determine number so that 0.2 <= total time < 2.0
        for i in range(1, 10):
            number = 10**i

            try:
                x = t.timeit(number)
            except:
                print(t.print_exc())
                return float('NaN')

            if x >= 0.2:
                break

    try:
        r = t.repeat(repeat, number)
    except:
        print(t.print_exc())
        return float('NaN')

    best = min(r)

    return best / number
开发者ID:AdveraHealth,项目名称:pint,代码行数:35,代码来源:bench.py

示例4: __execute

# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import print_exc [as 别名]
    def __execute(self, sql, kwargs):

        db = kwargs['db']
        hostType = kwargs['host_type']
        cursor = None
        if self.clientCursor:
            cursor = self.clientCursor
        else:
            cursor = SQLHub.connection[hostType]['cursor']

        ##Get the proc name for debug message##
        proc = ""
        if 'proc' in kwargs:
            proc = kwargs['proc']

        ##Caller requests no sql execution##
        if 'debug_noex' in kwargs:
            self.showDebug(db,
                           self.conf[hostType]['host'],
                           hostType,
                           proc,
                           sql,
                           None)
            return []

        ##Caller wants to sql execution time##
        if 'debug_show' in kwargs:

            def timewrapper():
                self.__cursorExecute(sql, kwargs, cursor)

            t = Timer(timewrapper)
            tmsg = ""
            try:
                tmsg = t.timeit(1)
            except:
                t.print_exc()

            self.showDebug(db,
                           self.conf[hostType]['host'],
                           hostType,
                           proc,
                           sql,
                           tmsg)
        else:
            self.__cursorExecute(sql, kwargs, cursor)

        ##Commit transaction##
        SQLHub.connection[hostType]['con_obj'].commit()

        return self.getData(cursor, kwargs)
开发者ID:rniwa,项目名称:datasource,代码行数:53,代码来源:SQLHub.py

示例5: main

# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import print_exc [as 别名]
def main():
    triplet = findPythagoreanTriplet( 1000 )

    if triplet:
        print triplet
        print reduce( lambda x, y: x * y, triplet )
    else:
        print 'Not found :('

    t = Timer( 'findPythagoreanTriplet( 1000 )', "from __main__ import findPythagoreanTriplet" )

    try:
        print t.timeit( 1 )
    except:
        print t.print_exc()
开发者ID:JeroenDeDauw,项目名称:ProjectEuler,代码行数:17,代码来源:p9.py

示例6: timeit

# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import print_exc [as 别名]
def timeit(stmt='pass', setup='pass', number=0, repeat=3):
    """Timer function with the same behaviour as running `python -m timeit `
    in the command line.

    :return: best elapsed time in seconds or NaN if the command failed.
    :rtype: float
    """

    if not setup:
        setup = 'pass'

    if not stmt:
        stmt = 'pass'

    key = (stmt, setup, number, repeat)

    if key in _CACHE:
        return _CACHE[key]

    t = Timer(stmt, setup)

    if not number:
        # determine number so that 0.2 <= total time < 2.0
        for i in range(1, 10):
            number = 10**i

            try:
                x = t.timeit(number)
            except:
                print(t.print_exc())
                return float('NaN')

            if x >= 0.2:
                break

    try:
        r = t.repeat(repeat, number)
    except:
        print(t.print_exc())
        return float('NaN')

    result = min(r) / number

    _CACHE[key] = result

    return result
开发者ID:hgrecco,项目名称:scipy_numba,代码行数:48,代码来源:bench.py

示例7: report

# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import print_exc [as 别名]
def report(stmt, setup, number=0, verbose=0, precision=3,
           repeat=default_repeat, timer=default_timer):
  sys.stdout.write("%50s -- " % stmt)
  t = Timer(stmt, setup, timer)
  if number == 0:
    # determine number so that 0.2 <= total time < 2.0
    for i in range(1, 10):
      number = 10 ** i
      try:
        x = t.timeit(number)
      except Exception:
        t.print_exc()
        return 1
      if verbose:
        print("%d loops -> %.*g secs" % (number, precision, x))
      if x >= 0.2:
        break
  try:
    r = t.repeat(repeat, number)
  except Exception:
    t.print_exc()
    return 1
  best = min(r)
  if verbose:
    print("raw times:", " ".join(["%.*g" % (precision, x) for x in r]))
  sys.stdout.write("%d loops, " % number)
  usec = best * 1e6 / number
  if usec < 1000:
    print("best of %d: %.*g usec per loop" % (repeat, precision, usec))
  else:
    msec = usec / 1000
    if msec < 1000:
      print("best of %d: %.*g msec per loop" % (repeat, precision, msec))
    else:
      sec = msec / 1000
      print("best of %d: %.*g sec per loop" % (repeat, precision, sec))
开发者ID:RoboTeddy,项目名称:mom,代码行数:38,代码来源:speed.py

示例8: benchmark

# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import print_exc [as 别名]
def benchmark(number=0, precision=3, verbose=True):
    repeat = default_repeat
    t = Timer(_benchmark)
    if number == 0:
        # determine number so that 0.2 <= total time < 2.0
        for i in range(1, 10):
            number = 10 ** i
            try:
                x = t.timeit(number)
            except:
                t.print_exc()
                return 1
            if verbose:
                print "%d loops -> %.*g secs" % (number, precision, x)
            if x >= 0.2:
                break
    try:
        r = t.repeat(repeat, number)
    except:
        t.print_exc()
        return 1
    best = min(r)
    if verbose:
        print "raw times:", " ".join(["%.*g" % (precision, x) for x in r])
    print "%d loops," % number,
    usec = best * 1e6 / number
    if usec < 1000:
        print "best of %d: %.*g usec per loop" % (repeat, precision, usec)
    else:
        msec = usec / 1000
        if msec < 1000:
            print "best of %d: %.*g msec per loop" % (repeat, precision, msec)
        else:
            sec = msec / 1000
            print "best of %d: %.*g sec per loop" % (repeat, precision, sec)
    return None
开发者ID:jorik041,项目名称:golismero,代码行数:38,代码来源:benchmark_url.py

示例9: work

# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import print_exc [as 别名]
         return 0
 setup = "\n".join(setup) or "pass"
 # Include the current directory, so that local imports work (sys.path
 # contains the directory of this script, rather than the current
 # directory)
 import os
 sys.path.insert(0, os.curdir)
 t = Timer(stmt, setup, timer)
 if number == 0:
     # determine number so that 0.2 <= total time < 2.0
     for i in range(1, 10):
         number = 10**i
         try:
             x = t.timeit(number)
         except:
             t.print_exc()
             return 1
         if verbose:
             print "%d loops -> %.*g secs" % (number, precision, x)
         if x >= 0.2:
             break
 try:
     r = t.repeat(repeat, number)
 except:
     t.print_exc()
     return 1
 if verbose:
     print "raw times:", " ".join(["%.*g" % (precision, x) for x in r])
 r = [int(x * 1e6 / number) for x in r]
 best = min(r)
 average = int(numpy.average(r))
开发者ID:pbrunet,项目名称:numpy-benchmarks,代码行数:33,代码来源:benchit.py

示例10: main

# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import print_exc [as 别名]
def main(args=None):
    """Main program, used when run as a script.

    The optional argument specifies the command line to be parsed,
    defaulting to sys.argv[1:].

    The return value is an exit code to be passed to sys.exit(); it
    may be None to indicate success.

    When an exception happens during timing, a traceback is printed to
    stderr and the return value is 1.  Exceptions at other times
    (including the template compilation) are not caught.
    """
    if not args:
        args = sys.argv[1:]
    import getopt
    try:
        opts, args = getopt.getopt(args, 'n:s:r:tcvh',
                                   ['number=', 'setup=', 'repeat=',
                                    'time', 'clock', 'verbose', 'help'])
    except getopt.error as err:
        print(err)
        print("use -h/--help for command line help")
        return 2
    timer = default_timer
    stmt = "\n".join(args) or "pass"
    number = 0  # auto-determine
    setup = []
    repeat = default_repeat
    verbose = 0
    precision = 3
    for o, a in opts:
        if o in ("-n", "--number"):
            number = int(a)
        if o in ("-s", "--setup"):
            setup.append(a)
        if o in ("-r", "--repeat"):
            repeat = int(a)
            if repeat <= 0:
                repeat = 1
        if o in ("-t", "--time"):
            timer = time.time
        if o in ("-c", "--clock"):
            timer = time.clock
        if o in ("-v", "--verbose"):
            if verbose:
                precision += 1
            verbose += 1
        if o in ("-h", "--help"):
            print(__doc__)
            return 0
    setup = "\n".join(setup) or "pass"
    # Include the current directory, so that local imports work (sys.path
    # contains the directory of this script, rather than the current
    # directory)
    import os
    sys.path.insert(0, os.curdir)
    t = Timer(stmt, setup, timer)
    if number == 0:
        # determine number so that 0.2 <= total time < 2.0
        for i in range(1, 10):
            number = 10**i
            try:
                x = t.timeit(number)
            except:
                t.print_exc()
                return 1
            if verbose:
                print("%d loops -> %.*g secs" % (number, precision, x))
            if x >= 0.2:
                break
    try:
        r = t.repeat(repeat, number)
    except:
        t.print_exc()
        return 1
    if verbose:
        print("raw times:", " ".join(["%.*g" % (precision, x) for x in r]))
    r = [int(x * 1e6 / number) for x in r]
    best = min(r)
    average = int(numpy.average(r))
    std = int(numpy.std(r))

    print(best, average, std)
开发者ID:serge-sans-paille,项目名称:numpy-benchmarks,代码行数:86,代码来源:benchit.py


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