Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a.b.c.d 和 a['b']['c']['d'],哪个性能更高? #26

Open
chaijinsong opened this issue Aug 14, 2019 · 0 comments
Open

a.b.c.d 和 a['b']['c']['d'],哪个性能更高? #26

chaijinsong opened this issue Aug 14, 2019 · 0 comments
Labels
Tips 一些小技巧,算不上文章但是有点用

Comments

@chaijinsong
Copy link
Owner

a.b.c.d 性能比 a['b']['c']['d'] 要高,因为a['b'] 这种方式其实还需要考虑 [] 中的内容作为一个变量的情况,所以多了对变量的计算。至于在ast层面上来看,两个表达式解析出来的结果前者会切割成7块,分别是a . b . c . d , 而后者则需要匹配左右括弧,多出一些匹配操作,由于要考虑[] 中会存在变量的情况,还需要通过作用域链寻找变量。整体上来说就比a.b.c.d 要慢。

@chaijinsong chaijinsong added the Tips 一些小技巧,算不上文章但是有点用 label Aug 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tips 一些小技巧,算不上文章但是有点用
Projects
None yet
Development

No branches or pull requests

1 participant