与同等功能相比,慢了多少python类? [英] How much slower python classes are compared to their equivalent functions?

查看:41
本文介绍了与同等功能相比,慢了多少python类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我开始学习Python时,我仅使用函数过程代码创建了一些应用程序.但是,现在我知道了,并且意识到,如果我使用类重写代码,则代码将更具可读性(从主观上更容易理解).

When I started learning Python, I created a few applications just using functions and procedural code. However, now I know classes and realized that the code can be much readable (and subjectively easier to understand) if I rewrite it with classes.

功能相比,等效的可能会慢多少?类中的初始化方法会在速度上产生很大的不同吗?

How much slower the equivalent classes may get compared to the functions in general? Will the initializer, methods in the classes make any considerable difference in speed?

推荐答案

否.

通常,基于使用类与否,您不会注意到性能上的任何差异.暗示的不同代码结构可能意味着一个比另一个要快,但无法确定哪个.

In general you will not notice any difference in performance based on using classes or not. The different code structures implied may mean that one is faster than the other, but it's impossible to say which.

总是编写要读取的代码,只有当它不够快时,才使其变得更快.请记住:过早的优化是万恶之源.

Always write code to be read, then if, and only if, it's not fast enough make it faster. Remember: Premature optimization is the root of all evil.

这篇关于与同等功能相比,慢了多少python类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆