> I had originally posted this on CF-Community, but I thought > that these results were interesting enough that others would > like to see them. I got into a discussion at my new job about > creating variables by the cfset tag or via a variable > assignment using cfscript.
I really hate these kinds of things. Don't take this as a personal attack - I certainly respect you, Larry, I know you're a smart guy. But these "which is faster" arguments end up the same as asking how many angels can dance on the head of a pin. > The consensus has been that when setting large blocks of > variables using cfscript is faster than cfset. The reason > that tags are slower is that when the template JITs, it adds > extra libraries into the class. When you use cfscript, it uses > fewer cftag libraries mentioned as Java import namespaces > because the cfscript code is closer to the native Java and > therefore requires less overhead (at least according to some > blog postings I've read). Also, the tag named import also > contains functionality the code may not be using. Therefore, > you have thinner JITs and faster code. Or so I thought. The consensus for these sorts of questions, if you can call it a consensus, is usually derived from a common-sense understanding of how things work. This approach is very appealing, because it lets you predict how something should behave. Unfortunately, this understanding is often completely wrong. It sounds reasonable enough, but is not based on actual observation and testing. Or, it's based on an implementation detail that changes over versions. Now, even according to the above description, there shouldn't be much difference between the two, because if you're replacing exactly one tag with a CFSCRIPT block, there would only be one library imported; the one for CFSET. And, there's no reason to believe that there's more unused functionality in a CFSET than a CFSCRIPT. But again, this interpretation I've just made is based on a common-sense understanding of how things work, and could very well be completely wrong, or different across different versions of CF. > Generally these results go against what's commonly thought. > However given that there was only about a half second > difference over a million iterations, is it really an > important difference? No, it isn't. And, even if it was, it could be completely different in other versions. It could be faster one way in one version, and faster the other way in other versions. Finally, the only way to truly identify whether something's a bottleneck is to test in parallel - load testing - rather than in serial. One thing repeated a million times in a single script almost always performs differently than a million scripts doing that one thing. And really finally, the vast majority of these "which is faster" things are completely insignificant in the overall performance of the application. The time spent writing your code to conform to the current belief about which is faster would be better spent optimizing database interaction, or caching, or asynchronous processing - things which will definitely make your application perform better. I'm not addressing this last point at you directly; I just see a lot of applications where a lot of effort has been spent on insignificant items like this, while the big honking query right in the same program does a table scan as a result of an unindexed column. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308450 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

