Getting “global name 'foo' is not defined” with Python's timeit

后端 未结 5 2038
臣服心动
臣服心动 2020-11-28 21:49

I\'m trying to find out how much time it takes to execute a Python statement, so I looked online and found that the standard library provides a module called timeit that pur

5条回答
  •  时光说笑
    2020-11-28 22:47

    t = timeit.Timer("foo()", "from __main__ import foo")
    

    Since timeit doesn't have your stuff in scope.

提交回复
热议问题