Python比C ++更快,更轻? [英] Is Python faster and lighter than C++?

查看:270
本文介绍了Python比C ++更快,更轻?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直认为Python的优点是代码的可读性和开发速度,但是时间和内存使用不如C ++那么好。

I've always thought that Python's advantages are code readibility and development speed, but time and memory usage were not as good as those of C++.

这些统计资料让我非常难过。

These stats struck me really hard.

您的经验告诉您关于Python和C ++的时间和内存使用情况?

What does your experience tell you about Python vs C++ time and memory usage?

推荐答案

我想你正在读这些统计数据不正确。它们表明Python比C ++慢了大约400倍,除了一个例外,Python更像是内存。然而,当涉及到源码大小时,Python胜出。

I think you're reading those stats incorrectly. They show that Python is up to about 400 times slower than C++ and with the exception of a single case, Python is more of a memory hog. When it comes to source size though, Python wins flat out.

我对Python的体验显示出同样明确的趋势,Python的速度慢10到100倍比C ++当做任何严重的数字嘎吱。这有很多原因,主要的是:a)Python被解释,而C ++被编译; b)Python没有原语,一切都包括内置类型(int,float等)是对象; c)Python列表可以保存不同类型的对象,因此每个条目都必须存储关于其类型的附加数据。这些都严重妨碍了运行时和内存消耗。

My experiences with Python show the same definite trend that Python is on the order of between 10 and 100 times slower than C++ when doing any serious number crunching. There are many reasons for this, the major ones being: a) Python is interpreted, while C++ is compiled; b) Python has no primitives, everything including the builtin types (int, float, etc.) are objects; c) a Python list can hold objects of different type, so each entry has to store additional data about its type. These all severely hinder both runtime and memory consumption.

这是没有理由忽略Python虽然。很多软件不需要很多时间或内存,即使使用100时间慢度因子。开发成本是Python以简单和简洁的风格赢得的地方。这种对开发成本的改进通常胜过额外的CPU和内存资源的成本。然而,当它没有时,C ++获胜。

This is no reason to ignore Python though. A lot of software doesn't require much time or memory even with the 100 time slowness factor. Development cost is where Python wins with the simple and concise style. This improvement on development cost often outweighs the cost of additional cpu and memory resources. When it doesn't, however, then C++ wins.

这篇关于Python比C ++更快,更轻?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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