使用空格而不是Tabs进行缩进的性能影响

时间:2022-03-30 16:54:43

I currently use soft tabs (i.e. spaces) for indenting my Ruby code, if I were to use hard tabs would it increase the performance when the code is interpreted? I assume it's faster to read one tab character than parse 4 space characters (however negligible).

我目前使用软选项卡(即空格)来缩进我的Ruby代码,如果我要使用硬选项卡,它会在解释代码时提高性能吗?我认为读取一个制表符比解析4个空格字符更快(但可以忽略不计)。

3 个解决方案

#1


11  

Do you have an idea of all the phases involved in interpreting from source? Only the very first one, lexical analysis, has to deal with whitespace, and in the case of whitespace, "deal with" means "ignore it". This phase only takes a tiny fraction of the total time, it's generally done using regular expression and pretty much has linear complexity. Constrast that with parsing, which can take ages in comparision. And interpreting is only somewhat viable because those two phases (plus a third, bytecode generation, in implementations that use bytecode) takes much less than the actual execution for nontrivial programs.

您是否了解从源代码解释所涉及的所有阶段?只有第一个,词法分析,必须处理空白,在空白的情况下,“处理”意味着“忽略它”。这个阶段只占总时间的一小部分,通常使用正则表达式完成,并且几乎具有线性复杂性。与解析相比,这可能需要花费很长时间才能进行比较。解释只是有点可行,因为这两个阶段(加上第三个字节码生成,在使用字节码的实现中)比非平凡程序的实际执行要少得多。

Don't worry about this. There is no difference anyone would ever notice. Honestly, I'd be surprised if you could measure a difference using time and a small program that does close to no actual work.

别担心这个。没有人会注意到任何差异。老实说,如果你能用时间和一个接近没有实际工作的小程序测量差异,我会感到惊讶。

#2


9  

Pretty sure that whatever negligible impact the parser may have between reading one byte for tabbed indentation vs. four bytes for spaces will be offset by the next person that has to read your code and fix your tabbed / spaced mess.

可以肯定的是,解析器在读取一个字节用于标签缩进与四个字节用于空格之间可能产生的微不足道的影响将被下一个必须读取代码并修复标签/间隔混乱的人所抵消。

Please use spaces. Signed, the next guy to read your code.

请使用空格。签名,下一个阅读你的代码的人。

#3


8  

Performance impact is ε, that is, a very small number greater than zero. The spaces only get read and parsed once, the Ruby code is then transformed into an intermediate form.

性能影响是ε,即大于零的非常小的数字。这些空间只能读取和解析一次,然后将Ruby代码转换为中间形式。

#1


11  

Do you have an idea of all the phases involved in interpreting from source? Only the very first one, lexical analysis, has to deal with whitespace, and in the case of whitespace, "deal with" means "ignore it". This phase only takes a tiny fraction of the total time, it's generally done using regular expression and pretty much has linear complexity. Constrast that with parsing, which can take ages in comparision. And interpreting is only somewhat viable because those two phases (plus a third, bytecode generation, in implementations that use bytecode) takes much less than the actual execution for nontrivial programs.

您是否了解从源代码解释所涉及的所有阶段?只有第一个,词法分析,必须处理空白,在空白的情况下,“处理”意味着“忽略它”。这个阶段只占总时间的一小部分,通常使用正则表达式完成,并且几乎具有线性复杂性。与解析相比,这可能需要花费很长时间才能进行比较。解释只是有点可行,因为这两个阶段(加上第三个字节码生成,在使用字节码的实现中)比非平凡程序的实际执行要少得多。

Don't worry about this. There is no difference anyone would ever notice. Honestly, I'd be surprised if you could measure a difference using time and a small program that does close to no actual work.

别担心这个。没有人会注意到任何差异。老实说,如果你能用时间和一个接近没有实际工作的小程序测量差异,我会感到惊讶。

#2


9  

Pretty sure that whatever negligible impact the parser may have between reading one byte for tabbed indentation vs. four bytes for spaces will be offset by the next person that has to read your code and fix your tabbed / spaced mess.

可以肯定的是,解析器在读取一个字节用于标签缩进与四个字节用于空格之间可能产生的微不足道的影响将被下一个必须读取代码并修复标签/间隔混乱的人所抵消。

Please use spaces. Signed, the next guy to read your code.

请使用空格。签名,下一个阅读你的代码的人。

#3


8  

Performance impact is ε, that is, a very small number greater than zero. The spaces only get read and parsed once, the Ruby code is then transformed into an intermediate form.

性能影响是ε,即大于零的非常小的数字。这些空间只能读取和解析一次,然后将Ruby代码转换为中间形式。