Yep - which is why I said it would be a rare and application-dependent thing ;)
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jim Davis Sent: Thursday, November 10, 2005 7:59 PM To: [email protected] Subject: RE: [CFCDev] Scoping Error From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Roland Collins Sent: Thursday, November 10, 2005 3:38 PM To: [email protected] Subject: RE: [CFCDev] Scoping Error >We've already been over this, but this can have performance implications when used with highly iterative operations. >Consider this (contrived, but simple) example: I agree. but have you actually tested this? The performance difference is REALLY small. Using your code I built one function which uses the function local, one which uses a directly declared function local variable and one which just returns the equation. I wrapped each in a getTickCount() and display the results. Here are some run times (I threw away the first one to allow for compile time): Local Time = 230 No Local Time = 200 No Local, No Middle-man Time = 201 Local Time = 270 No Local Time = 240 No Local, No Middle-man Time = 181 Local Time = 280 No Local Time = 210 No Local, No Middle-man Time = 191 Local Time = 221 No Local Time = 190 No Local, No Middle-man Time = 150 Local Time = 220 No Local Time = 180 No Local, No Middle-man Time = 170 Local Time = 210 No Local Time = 170 No Local, No Middle-man Time = 180 Local Time = 220 No Local Time = 191 No Local, No Middle-man Time = 160 So, yes, using the local was ALWAYS slower... but by only by a (very) small fraction of ms per iteration (remember these tests for 10,000 iterations each). (Mine isn't a very fast research server either.) I honestly don't think you'd ever be able to reliably measure a difference in a real application. Pretty much all techniques for improving development results in slower code (although it's hard to see after 10 years of optimization the OO paradigm itself is "slow" compared to straight procedural code for the same tasks). It's a pretty reliable rule of thumb that anything that makes code easier to write and easier to maintain will make code slower. ;^) Here's the code I used (not the best test, of course): <cfscript> function addA(a, b) { var local = StructNew(); local.result = arguments.a + arguments.b; return local.result; } function addB(a, b) { var result = arguments.a + arguments.b; return result; } function addC(a, b) { return arguments.a + arguments.b; } </cfscript> <cfset bTime = getTickCount() /> <cfloop from="1" to="10000" index="i"> <cfset result = addA(i, 100)> </cfloop> <cfset eTime = getTickCount() /> <cfoutput>Local Time = #eTime - bTime#<br></cfoutput> <cfset bTime = getTickCount() /> <cfloop from="1" to="10000" index="i"> <cfset result = addB(i, 100)> </cfloop> <cfset eTime = getTickCount() /> <cfoutput>No Local Time = #eTime - bTime#<br></cfoutput> <cfset bTime = getTickCount() /> <cfloop from="1" to="10000" index="i"> <cfset result = addC(i, 100)> </cfloop> <cfset eTime = getTickCount() /> <cfoutput>No Local, No Middle-man Time = #eTime - bTime#<br></cfoutput> Jim Davis ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com). An archive of the CFCDev list is available at www.mail-archive.com/[email protected] ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com). An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
