我很想知道目标成员进入时间。 更确切地说,在<代码>window的物体上,I m基准接入时间。 我认为,我可以自行解释大多数行为,但我觉得听取一些意见更好。
使用情况:不同财产的不同存取时间?
• 简单测量法,如:
var loop = 100000;
console.time( bench );
while(loop--){
if(window.JSON)
var foo = 0;
}
console.timeEnd( bench );
The first strange thing is, it makes a different which property I m looking up. For instance, window.JSON
seems to be faster to access, than window.localStorage
. There are other propertys/methods which can get accessed even faster.
Since there is no specification or defination within in the the ECMA-262 Language Specification, which order keys must have in an object, I guess each browser vendor implements it s own logic in which order keys
are stored in memory.
Could this be an explanation for this behavior? Like, JSON
is one of the very first keys and location
is more at the end? (In my test environment at least)
<>->-
我注意到的另一件事是,电话if(JSON)
略高于if(window.JSON)
。 如果我们忘记,由于可能的参考错误,你总是应该做第二次呼吁,那么这些呼吁应当有同样的准入时间。 I mnow of ECMAscripts conduct on nested member lookups
(A nested member will causes the Javascriptenergy to go through the Object member resolution, each time a dot isborn/strong>, so window.href
速度必须低于<代码> 所在地.href,但在这种情况下,window.JSON
之间是否有差别?
为此,了解<代码>window的最快途径 物体拥有特定财产/方法即使用IN
的操作者。 就上述例子而言,这大约是十倍。