How do I measure the execution time of python unit

2020-05-21 08:54发布

Is there a way to time the execution time of individual Python tests which are run by nosetests ?

2条回答
淡お忘
2楼-- · 2020-05-21 09:32

Alternatively:

python -m cProfile -o profile.out `which nosetests` .

The output from can be viewed using, for example, runsnakerun, which makes it visually very obvious where your performance problems are. (e.g. it might be in a common method that many tests indirectly call)

查看更多
一纸荒年 Trace。
3楼-- · 2020-05-21 09:39

You might try the nose plug-in posted here: https://github.com/mahmoudimus/nose-timer (or available via pip / PyPi). You can also use the built-in plugin --with-profile to do more serious profiling.

查看更多
登录 后发表回答