Performance of Google chrome vs nodejs (v8)?

后端 未结 3 718
暖寄归人
暖寄归人 2021-02-01 08:42

\"enter

Example

     console.time("Test");
     for(var i=0; i         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-01 09:24

    In a web browser(Chrome), declaring the variable i outside of any function scope makes it global and therefore binds to window object. As a result, running this code in a web browser requires repeatedly resolving the property within the heavily populated window namespace in each iteration of the for loop.

    In Node.js however, declaring any variable outside of any function’s scope binds it only to the module scope (not the window object) which therefore makes it much easier and faster to resolve.

    We will get more or less same execution speed when we wrap the above code in function.

提交回复
热议问题