javascript - Performance of Google chrome vs nodejs (v8)? -


enter image description here

example

     console.time("test");      for(var i=0; <2500000; +=1 ){              // loop around      }      console.timeend("test"); 

the above code runs faster in nodejs google chrome. why node.js faster google chrome both using chrome v8 engine

note

average speed

 google chrome  - 1518.021ms    node.js - 4 ms 

any idea difference execution speed?

in web browser(chrome), declaring variable i outside of function scope makes global , therefore binds window object. result, running code in web browser requires repeatedly resolving property within heavily populated window namespace in each iteration of the for loop.

in node.js however, declaring variable outside of function’s scope binds module scope (not the window object) therefore makes easier , faster resolve.

we more or less same execution speed when wrap above code in function.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -