简体   繁体   English

评论数组值而不是删除它们

[英]Commenting Array values instead of Removing them

Just out of curiosity, Is there any difference in terms of Performance between Removing a value from the Array and Just commenting it instead of removing it from the Array.只是出于好奇,从数组中删除一个值和只是评论它而不是从数组中删除它在性能方面有什么区别。

We have an array let arr = [{a:1},{b:2},{c:3},{d:4}] and have to remove the last value.我们有一个数组let arr = [{a:1},{b:2},{c:3},{d:4}]并且必须删除最后一个值。 instead of using array methods, we either remove the value manually or comment it.我们不使用数组方法,而是手动删除该值或对其进行注释。

We have two Arrays ie, let arr1 = [{a:1},{b:2},{c:3}] and我们有两个 Arrays 即let arr1 = [{a:1},{b:2},{c:3}]

    let arr2 = [
    {a:1},
    {b:2},
    {c:3},
    // {d:4}
    ]

Here in arr1 the last value is removed from the code and in arr2 the value is commented.在 arr1 中,最后一个值被从代码中删除,而在 arr2 中,该值被注释掉。 Functionality wise the two arrays will give 3 as their length, is there any performance issue if we have commented code inside the array or any issue in general?功能方面,两个 arrays 将给出 3 作为它们的长度,如果我们在数组中注释了代码或一般有任何问题,是否有任何性能问题?

comments are scanned over like whitespace so they wont be processed.评论像空白一样被扫描,因此它们不会被处理。 However if you are looking at work done too then it actually does affect performance with respect to time但是,如果您也在查看已完成的工作,那么它实际上确实会影响时间方面的性能

No, commented out code is never executed and completely ignored so no performance issue really other than the size of your file would be a bit larger.不,注释掉的代码永远不会执行并且完全被忽略,因此除了文件大小之外,没有任何性能问题会更大。

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

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