Cpy和Python的效率对比

WBOY
Release: 2016-06-10 15:17:03
Original
1359 people have browsed it

Python 语言的初学者, 特别是"惊奇者"(也就是那种第一眼就被毫无意义的某些特性吸引, 之后持续说服自己的人)认为 Python 不需要 C 语言的 for 语句, 因为他们能用优雅的 Python for 来代替类 C 的 for.

Cpy 的循环方式:

复制代码 代码如下:

for(i=s; i }

Python 的循环方式:
复制代码 代码如下:

for i in range(num)[s:e:step]:

最近, 我写了一个循环 100000000 遍的代码, 不幸的是(也正是所预计的), Python 把机器内存吃光了, 并让我的 Windows 报虚拟内存不足的错误. 可怜的 Python 只能被操作系统无情地 kill 掉而不给任何机会.

而 Cpy 的循环却毫无压力, 只占用了很小的内存.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!