November 11th, 2012, 08:49 AM
Looking for opinions
1. Function expressions run slower than function declarations.
2. Local variables are faster than global
3. Prototype can save resource use in certain cases
My question is this: at what point would you say prototype use would become worthwhile, given the fact that it requires the use of function expressions, and is not evaluated until runtime, and therefore runs more slowly? It also makes code more bloated. How many instances of a function would you say would be required to make prototyping noticeably the better option? Thanks in advance
November 11th, 2012, 10:56 AM
November 11th, 2012, 11:35 AM
Hi, it's less about what I'm building and more about disputing a general practice where I work. In the shop I'm currently employed at, pretty much every function is prototyped, and I strongly believe that in most cases this is not only wasteful in terms of bulk of code, but also actually less efficient and slower. I just wanted to see if anybody else had an opinion.
What I've discovered in writing for mobile devices, particularly older, slower ones, is that even the practice of name spacing, which adds an extra layer to the scope chain, has a performance affect in some of these older and pathetic processors.
If you're working with devices that slow, even using a function expression as opposed to a declaration taxes them too much. Having them try to evaluate and execute the code at runtime is simply too much for these little things.
But regardless of what device you're writing for, it would still mean that these practices are actually slower overall. You may not notice them on desktop, or newer mobile devices, but I think if they were bench tested, it would show up. You can find some of these tests on JSperf. Thanks for your reply-AC