Hello,
I actually did a test:
<cfif not isDefined("application.imgobject")>
<cfobject component="#application.cfcbase#common" name="com">
<cfset application.imgobject = com>
</cfif>
<cfset scaleMethod = "myTestMethod">
<cfset tt = getTickcount()>
<cfloop index="m" from="1" to="1000" step="1">
<cfinvoke method="#scaleMethod#" returnvariable="retVar"
component="#application.imgobject#">
<cfinvokeargument name="t1" value="123">
<cfinvokeargument name="t2" value="123">
</cfinvoke>
</cfloop>
<cfoutput>M1: #getTickCount()-tt#<br><br></cfoutput>
<cfset tt = getTickcount()>
<cfloop index="m" from="1" to="1000" step="1">
<cfset retVar = evaluate("application.imgobject." & scaleMethod &
"(123,123)")>
</cfloop>
<cfoutput>M2: #getTickCount()-tt#</cfoutput>
where the function is:
<cffunction name="myTestMethod" access="public" returntype="string"
output="false" displayname="Get full website address without http or https"
hint="This is used by CFCs that need to know website address, webpages use
value from application.cfm">
<cfargument name="t1" required="true" type="numeric" displayname="sort
modifier" hint="">
<cfargument name="t2" required="true" type="numeric" displayname="sort
modifier" hint="">
<cfreturn 1000>
</cffunction>
Turns out the cfinvoke doesn't support 'object' parameter as in your
example. It also turns out that evaluate is still not as fast as some people
claimed. I agree that using evaluate in almost all cases is a bad idea,
through saying so in a phone interview most likely costed me a contract :(
cfinvoke is 50% faster then using evaluate.
TK
-----Original Message-----
From: Barney Boisvert [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 14, 2006 12:53 PM
To: CF-Talk
Subject: Re: Dynamically calling methods in a CFC
While it may not be as bad as it once was in terms performance-wise,
it's still bad for various other reasons. If you feel you need to use
evaluate(), chances are good you're missing a language facet or you
have a design flaw somewhere. It also often results in less readable
code, because you have to manually do string parsing and evaluation,
rather than relying on native language constructs.
And if the handful of microseconds matter to your application's
performance, using CF is a probably bad choice anyway.
cheers,
barneyb
On 9/14/06, Tom Kitta <[EMAIL PROTECTED]> wrote:
> Didn't we go over on this list the fact that evaluate() is not very bad
> anymore? I wonder which method would be faster, the invoke or the
evaluate()
> in CF7.
>
> TK
>
> -----Original Message-----
> From: Barney Boisvert [mailto:[EMAIL PROTECTED]
> Sent: Thursday, September 14, 2006 12:34 PM
> To: CF-Talk
> Subject: Re: Dynamically calling methods in a CFC
>
>
> evaluate() is satan. CFINVOKE will do the job. It can call methods
> statically, or on a preexisting object (per my previous email).
>
> cheers,
> barneyb
--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/
Got Gmail? I have 100 invites.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253144
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4