• Home
  • Raw
  • Download

Lines Matching +full:- +full:- +full:setup

12     python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [--] [statement]
15 -n/--number N: how many times to execute 'statement' (default: see below)
16 -r/--repeat N: how many times to repeat the timer (default 3)
17 -s/--setup S: statement to be executed once initially (default 'pass')
18 -t/--time: use time.time() (default on Unix)
19 -c/--clock: use time.clock() (default on Windows)
20 -v/--verbose: print raw timing results; repeat for more digits precision
21 -h/--help: print this usage message and exit
22 --: separate options from statement, use when statement starts with -
25 A multi-line statement may be given by specifying each line as a
27 argument in quotes and using leading spaces. Multiple -s options are
30 If -n is not given, a suitable number of loops is calculated by trying
40 repeat the timing a few times and use the best time. The -r option is
51 use python -O for the older versions to avoid timing SET_LINENO
66 dummy_src_name = "<timeit-src>"
78 # in Timer.__init__() depend on setup being indented 4 spaces and stmt
82 %(setup)s
87 return _t1 - _t0
91 """Helper to reindent a multi-line statement."""
94 def _template_func(setup, func): argument
97 setup()
102 return _t1 - _t0
109 statement used for setup, and a timer function. Both statements
110 default to 'pass'; the timer function is platform-dependent (see
118 multi-line string literals.
121 def __init__(self, stmt="pass", setup="pass", timer=default_timer): argument
127 if isinstance(setup, basestring):
128 compile(setup, dummy_src_name, "exec")
129 compile(setup + '\n' + stmt, dummy_src_name, "exec")
133 if isinstance(setup, basestring):
134 setup = reindent(setup, 4)
135 src = template % {'stmt': stmt, 'setup': setup, 'init': ''}
136 elif hasattr(setup, '__call__'):
137 src = template % {'stmt': stmt, 'setup': '_setup()',
139 ns['_setup'] = setup
141 raise ValueError("setup is neither a string nor callable")
148 if isinstance(setup, basestring):
149 _setup = setup
150 def setup(): function
152 elif not hasattr(setup, '__call__'):
153 raise ValueError("setup is neither a string nor callable")
154 self.inner = _template_func(setup, stmt)
188 To be precise, this executes the setup statement once, and
192 to one million. The main statement, the setup statement and
234 def timeit(stmt="pass", setup="pass", timer=default_timer, argument
237 return Timer(stmt, setup, timer).timeit(number)
239 def repeat(stmt="pass", setup="pass", timer=default_timer, argument
242 return Timer(stmt, setup, timer).repeat(repeat, number)
266 ["number=", "setup=", "repeat=",
270 print "use -h/--help for command line help"
274 number = 0 # auto-determine
275 setup = []
280 if o in ("-n", "--number"):
282 if o in ("-s", "--setup"):
283 setup.append(a)
284 if o in ("-r", "--repeat"):
288 if o in ("-t", "--time"):
290 if o in ("-c", "--clock"):
292 if o in ("-v", "--verbose"):
296 if o in ("-h", "--help"):
299 setup = "\n".join(setup) or "pass"
307 t = Timer(stmt, setup, timer)
318 print "%d loops -> %.*g secs" % (number, precision, x)