问题描述
从事不同的项目,只要任务完成,我就可以选择不同的编程语言.
Working on different projects I have the choice of selecting different programming languages, as long as the task is done.
我想知道用 Python 编写程序与用 C 编写程序在性能方面的真正区别是什么.
I was wondering what the real difference is, in terms of performance, between writing a program in Python, versus doing it in C.
要完成的任务多种多样,例如排序文本文件、磁盘访问、网络访问、文本文件解析.
The tasks to be done are pretty varied, e.g. sorting textfiles, disk access, network access, textfile parsing.
例如,在 C 和 Python 中使用相同算法对文本文件进行排序之间真的有明显的区别吗?
Is there really a noticeable difference between sorting a textfile using the same algorithm in C versus Python, for example?
根据您的经验,鉴于当前 CPU (i7) 的强大功能,这是否真的有显着差异(考虑到它是一个不会使系统瘫痪的程序).
And in your experience, given the power of current CPU's (i7), is it really a noticeable difference (Consider that its a program that doesnt bring the system to its knees).
推荐答案
使用 python 直到出现性能问题.如果您曾经弄清楚问题是什么(通常不是您预先猜到的).然后解决可能是算法或数据结构更改的特定性能问题.在极少数情况下,您的问题确实需要 C,那么您可以只用 C 编写该部分并从您的 Python 代码中使用它.
Use python until you have a performance problem. If you ever have one figure out what the problem is (often it isn't what you would have guessed up front). Then solve that specific performance problem which will likely be an algorithm or data structure change. In the rare case that your problem really needs C then you can write just that portion in C and use it from your python code.
这篇关于Python 和 C 之间的性能差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!