简体   繁体   English

是否影响程序中的 memory 消耗

[英]Does It affect the memory consumption in program

return sum(x for x in list)
vs 
for x in list:
   sum+=x
return sum

does 1st the statement execute faster and the memory used by both the programs is same or not.第一个语句执行得更快,两个程序使用的 memory 是否相同。 I am not able to find this answer specifically/我无法专门找到这个答案/

There is nearly no difference for most cases.大多数情况下几乎没有区别。 If you are really memory constrained, use sum because it is optimised (but Python and native lists should be a bigger concern to you).如果您真的受 memory 限制,请使用sum ,因为它已经过优化(但 Python 和本机列表应该是您更关心的问题)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM