Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中timeit模块中的-s标志是什么?_Python - Fatal编程技术网

Python中timeit模块中的-s标志是什么?

Python中timeit模块中的-s标志是什么?,python,Python,来自Python食谱 python timeit.py -s"import random" -s"x=range(100000); random.shuffle(x)" "sorted(x)" 10 loops, best of 3: 152 msec per loop -s标志的作用是什么? 在线搜索,python帮助等等。但是没有找到一个好的解释。谢谢。来自Python内置的help() 重新阅读文档时,可能是“最初执行一次”的措辞不够清晰(即,文档中没有说明为什么能够这样做是一项有用的功

来自Python食谱

python timeit.py -s"import random" -s"x=range(100000); random.shuffle(x)" "sorted(x)"
10 loops, best of 3: 152 msec per loop
-s
标志的作用是什么?
在线搜索,python帮助等等。但是没有找到一个好的解释。谢谢。

来自Python内置的
help()


重新阅读文档时,可能是“最初执行一次”的措辞不够清晰(即,文档中没有说明为什么能够这样做是一项有用的功能)

-s
设置行的好处是它们在定时循环外部执行,但定时循环内部的代码可以看到它们定义的值

因此,在引用的示例中,只有排序的(x)部分是定时的-实际创建的
x
发生在设置代码之前。

或参见
>>>import timeit
>>>help(timeit)

....
Command line usage:
    python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [--] [statement]

Options:
  -n/--number N: how many times to execute 'statement' (default: see below)
  -r/--repeat N: how many times to repeat the timer (default 3)
  -s/--setup S: statement to be executed once initially (default 'pass')
....