Performance Implications of Using Spaces Instead of Tabs for Indentation

余生颓废 提交于 2019-12-05 02:37:56

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!