Python быстрее и легче, чем C++? [закрытый]

Как указывается в этом открытом выпуске , заполнение полей получателя и темы черновика электронной почты из дополнения, расширяющего пользовательский интерфейс, в настоящее время не поддерживается.

83
задан igouy 21 August 2016 в 16:10
поделиться

8 ответов

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.

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.

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.

214
ответ дан 24 November 2019 в 08:40
поделиться

All the slowest (>100x) usages of Python on the shootout are scientific operations that require high GFlop/s count. You should NOT use python for those anyways. The correct way to use python is to import a module that does those calculations, and then go have a relaxing afternoon with your family. That is the pythonic way :)

126
ответ дан 24 November 2019 в 08:40
поделиться

My experience is the same as the benchmarks. Python can be slow and uses more memory. I write much, much less code and it works the first time with much less debugging. Since it manages memory for me, I don't have to do any memory management, saving hours of chasing down core leaks.

What's your question?

25
ответ дан 24 November 2019 в 08:40
поделиться

Размер источника не очень подходит для измерения. Например, следующий скрипт оболочки:

cat foobar

намного короче, чем его эквиваленты Python или C ++.

14
ответ дан 24 November 2019 в 08:40
поделиться

Также: Psyco vs. C ++ .

Это все еще плохое сравнение, так как никто не будет делать тесты на число хрустящих вещей, как правило, на чистом Python. Лучше было бы сравнить производительность реалистичных приложений или C ++ с NumPy, чтобы понять, будет ли ваша программа заметно медленнее.

6
ответ дан 24 November 2019 в 08:40
поделиться

Это та же проблема с управляемым и простым в использовании языком программирования, как всегда - они медленные (и иногда потребляют память).

Это языки, чтобы сделать контроль, а не обработку. Если бы мне пришлось написать приложение для преобразования изображений и использовать Python, вся обработка могла бы быть написана на C ++ и подключена к Python через привязки, тогда как интерфейс и управление процессом были бы определенно Python.

2
ответ дан 24 November 2019 в 08:40
поделиться

I think those stats show that Python is much slower and uses more memory for those benchmarks - are you sure you're reading them the right way up?

In my experience, which is mostly with writing network- and file-system-bound programs in Python, Python isn't significantly slower in any way that matters. For that kind of work, its benefits outweigh its costs.

2
ответ дан 24 November 2019 в 08:40
поделиться

Проблема в том, что у вас есть два разных языка, которые решают две разные проблемы ... это как сравнение C ++ с ассемблером.

Python для быстрой разработки приложений и для случаев, когда производительность минимальное беспокойство.

C ++ не для быстрой разработки приложений и наследует наследование скорости от C - для низкоуровневого программирования.

3
ответ дан 24 November 2019 в 08:40
поделиться
Другие вопросы по тегам:

Похожие вопросы: