变量名称长度与性能 [英] Variable name length vs performance
问题描述
如何可能,变量名称长度的巨大差异不会导致javascript中任何性能下降?
How is it possible, that a huge difference in variable name length won't cause any performance loss in javascript?
宣布 var a = 0;
需要相同的时间来声明 var aaaaaaaaaaaaaaaa = 0;
即使用它们执行计算也需要相同的时间。
It takes the same time to declare var a = 0;
as it takes to declare var aaaaaaaaaaaaaaa = 0;
It takes the same time even to execute computations with them.
推荐答案
基于@ Cerbrus的评论:
它在实践中导致可忽略小的性能差异,但仅在声明变量时。
之后,它会在内存中获得特定的地址,并将其称为此地址,而不是变量名,所以它不会再影响性能。
It causes a negligibly small performance difference in practise, but only when declaring the variable. Afterwards, it gets a specific address in the memory, and it is referred as this address, not the variable name, so it won't affect the performance anymore.
但是,谈论脚本语言主要用于Web,较短的变量名称可以减少文件大小,并加快页面加载速度。这是JS编译器的功能之一,例如 Google的。
However, talking about a scripting language used mostly on web, shorter variable names can reduce the filesize, and speed up pageloads. This is one of the features of the JS compilers, such as Google's.
这篇关于变量名称长度与性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!