使用空格而不是制表符缩进的性能影响 [英] Performance Implications of Using Spaces Instead of Tabs for Indentation

查看:236
本文介绍了使用空格而不是制表符缩进的性能影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用软标签(即空格)缩进我的Ruby代码,如果我使用硬标签,它会提高代码解释的性能?我假设读取一个制表符字符比解析4个空格字符更快(但可忽略不计)。

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).

推荐答案

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

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.

这篇关于使用空格而不是制表符缩进的性能影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆