Performance differences between Python and C

后端 未结 14 1244
闹比i
闹比i 2020-12-31 08:02

Working on different projects I have the choice of selecting different programming languages, as long as the task is done.

I was wondering what the real difference is

14条回答
  •  攒了一身酷
    2020-12-31 08:41

    (Assumption - The question implies that the author is familiar with C but not Python, therefore I will base my answer with that in mind.)

    I was wondering what the real difference is, in terms of performance, between writing a program in Python, versus doing it in C.

    C will almost certainly be faster unless it is implemented poorly, but the real questions are:

    • What are the development implications (development time, maintenance, etc.) for either implementation?
    • Is the performance benefit significant?

    Learning Python can take some time, but there are Python modules that can greatly speed development time. For example, the csv module in Python makes reading and writing csv easy. Also, Python strings, arrays, maps, and other objects make it more flexible than plain C and more elegant, in my opinion, than the equivalent C++. Some things like network access may be much quicker to develop in Python as well.

    However, it may take time to learn how to program Python well enough to accomplish your task. Since you are concerned with performance, I suggest trying a simple task, such as sorting a text file, in both C and Python. That will give you a better baseline on both languages in terms of performance, development time, and possibly maintenance.

提交回复
热议问题