<s> """<STR_LIT>""" <EOL> from __future__ import print_function , division <EOL> import py <EOL> from py . __ . test . item import Item <EOL> from py . __ . test . terminal . terminal import TerminalSession <EOL> from math import ceil as _ceil , floor as _floor , log10 <EOL> import timeit <EOL> from inspect import getsource <EOL> from sympy . core . compatibility import exec_ , range <EOL> units = [ "<STR_LIT:s>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> scaling = [ <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> unitn = dict ( ( s , i ) for i , s in enumerate ( units ) ) <EOL> precision = <NUM_LIT:3> <EOL> class Directory ( py . test . collect . Directory ) : <EOL> def filefilter ( self , path ) : <EOL> b = path . purebasename <EOL> ext = path . ext <EOL> return b . startswith ( '<STR_LIT>' ) and ext == '<STR_LIT>' <EOL> class Module ( py . test . collect . Module ) : <EOL> def funcnamefilter ( self , name ) : <EOL> return name . startswith ( '<STR_LIT>' ) or name . startswith ( '<STR_LIT>' ) <EOL> class Timer ( timeit . Timer ) : <EOL> def __init__ ( self , stmt , setup = '<STR_LIT>' , timer = timeit . default_timer , globals = globals ( ) ) : <EOL> self . timer = timer <EOL> stmt = timeit . reindent ( stmt , <NUM_LIT:8> ) <EOL> setup = timeit . reindent ( setup , <NUM_LIT:4> ) <EOL> src = timeit . template % { '<STR_LIT>' : stmt , '<STR_LIT>' : setup } <EOL> self . src = src <EOL> code = compile ( src , timeit . dummy_src_name , "<STR_LIT>" ) <EOL> ns = { } <EOL> exec_ ( code , globals , ns ) <EOL> self . inner = ns [ "<STR_LIT>" ] <EOL> class Function ( py . __ . test . item . Function ) : <EOL> def __init__ ( self , * args , ** kw ) : <EOL> super ( Function , self ) . __init__ ( * args , ** kw ) <EOL> self . benchtime = None <EOL> self . benchtitle = None <EOL> def execute ( self , target , * args ) : <EOL> src = getsource ( target ) <EOL> src = '<STR_LIT:\n>' . join ( src . splitlines ( ) [ <NUM_LIT:1> : ] ) <EOL> if target . func_doc is not None : <EOL> self . benchtitle = target . func_doc <EOL> else : <EOL> self . benchtitle = src . splitlines ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> timer = Timer ( src , globals = target . func_globals ) <EOL> if self . name . startswith ( '<STR_LIT>' ) : <EOL> repeat = <NUM_LIT:3> <EOL> number = <NUM_LIT:1> <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:10> ) : <EOL> t = timer . timeit ( number ) <EOL> if t >= <NUM_LIT> : <EOL> number *= ( <NUM_LIT> / t ) <EOL> number = int ( _ceil ( number ) ) <EOL> break <EOL> if t <= <NUM_LIT> : <EOL> number *= <NUM_LIT:10> <EOL> else : <EOL> number *= ( <NUM_LIT> / t ) <EOL> number = int ( _ceil ( number ) ) <EOL> break <EOL> self . benchtime = min ( timer . repeat ( repeat , number ) ) / number <EOL> else : <EOL> self . benchtime = timer . timeit ( <NUM_LIT:1> ) <EOL> class BenchSession ( TerminalSession ) : <EOL> def header ( self , colitems ) : <EOL> super ( BenchSession , self ) . header ( colitems ) <EOL> def footer ( self , colitems ) : <EOL> super ( BenchSession , self ) . footer ( colitems ) <EOL> self . out . write ( '<STR_LIT:\n>' ) <EOL> self . print_bench_results ( ) <EOL> def print_bench_results ( self ) : <EOL> self . out . write ( '<STR_LIT>' ) <EOL> self . out . write ( '<STR_LIT>' ) <EOL> self . out . write ( '<STR_LIT>' ) <EOL> self . out . write ( '<STR_LIT:\n>' ) <EOL> results = [ ] <EOL> for item , outcome in self . _memo : <EOL> if isinstance ( item , Item ) : <EOL> best = item . benchtime <EOL> if best is None : <EOL> tstr = '<STR_LIT>' <EOL> else : <EOL> if best > <NUM_LIT:0.0> : <EOL> order = min ( - int ( _floor ( log10 ( best ) ) // <NUM_LIT:3> ) , <NUM_LIT:3> ) <EOL> else : <EOL> order = <NUM_LIT:3> <EOL> tstr = "<STR_LIT>" % ( <EOL> precision , best * scaling [ order ] , units [ order ] ) <EOL> results . append ( [ item . name , tstr , item . benchtitle ] ) <EOL> wm = [ <NUM_LIT:0> ] * len ( units ) <EOL> we = [ <NUM_LIT:0> ] * len ( units ) <EOL> for s in results : <EOL> tstr = s [ <NUM_LIT:1> ] <EOL> n , u = tstr . split ( ) <EOL> un = unitn [ u ] <EOL> try : <EOL> m , e = n . split ( '<STR_LIT:.>' ) <EOL> except ValueError : <EOL> m , e = n , '<STR_LIT>' <EOL> wm [ un ] = max ( len ( m ) , wm [ un ] ) <EOL> we [ un ] = max ( len ( e ) , we [ un ] ) <EOL> for s in results : <EOL> tstr = s [ <NUM_LIT:1> ] <EOL> n , u = tstr . split ( ) <EOL> un = unitn [ u ] <EOL> try : <EOL> m , e = n . split ( '<STR_LIT:.>' ) <EOL> except ValueError : <EOL> m , e = n , '<STR_LIT>' <EOL> m = m . rjust ( wm [ un ] ) <EOL> e = e . ljust ( we [ un ] ) <EOL> if e . strip ( ) : <EOL> n = '<STR_LIT:.>' . join ( ( m , e ) ) <EOL> else : <EOL> n = '<STR_LIT:U+0020>' . join ( ( m , e ) ) <EOL> txt = '<STR_LIT>' <EOL> for i in range ( len ( units ) ) : <EOL> if i == un : <EOL> txt += n <EOL> else : <EOL> txt += '<STR_LIT:U+0020>' * ( wm [ i ] + we [ i ] + <NUM_LIT:1> ) <EOL> s [ <NUM_LIT:1> ] = '<STR_LIT>' % ( txt , u ) <EOL> for i in range ( <NUM_LIT:2> ) : <EOL> w = max ( len ( s [ i ] ) for s in results ) <EOL> for s in results : <EOL> s [ i ] = s [ i ] . ljust ( w ) <EOL> for s in results : <EOL> self . out . write ( '<STR_LIT>' % tuple ( s ) ) <EOL> def main ( args = None ) : <EOL> from py . __ . test import defaultconftest <EOL> defaultconftest . Directory = Directory <EOL> defaultconftest . Module = Module <EOL> defaultconftest . Function = Function <EOL> config = py . test . config <EOL> config . _getsessionclass = lambda : BenchSession <EOL> py . test . cmdline . main ( args ) </s>
