如何在性能方面比较 python 函数?

How do I compare python functions in terms of performance?(如何在性能方面比较 python 函数?)

本文介绍了如何在性能方面比较 python 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了 2 个功能完全相同的功能,但我不知道哪个更快更好.如何比较这两个函数,看看哪一个在性能和所有方面都更好?

I have written 2 functions doing the exact same thing, but I don't know which one is faster and better. How do I compare these 2 functions to see which one is better in terms of performance and everything?

推荐答案

timeit 模块就可以了.

The timeit module will do ya.

这篇关于如何在性能方面比较 python 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在性能方面比较 python 函数?