Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFC Performance Overhead

New Here ,
Aug 27, 2008 Aug 27, 2008
Hi All,
I was trying to measure the performance overhead of using a CFC versus using a plain cfinclude, and I have come up with some really strange results. I hope someone can throw a light on what is going on.
So basically I made 3 files.
1. testCFC.cfm: This is the file which I run and which either contains a call to the compTest.cfc or includes the compTest.cfm
2. compTest.cfm: This is the included file and contains a simple cfloop doing something
3. compTest.cfc: This is the cfc which contains the same simple cfloop doing something.

I measured the tickcount before the cfc call and after the cfc had returned and I got 210 ms.
When I did the cfinclude I got 150 ms. So it seems that the CFC overhead was 33%. But that seemed unreasonably high, so I measured the time taken to run the loop inside the cfc and that was also 210 ms. Of something is amiss here because the time taken to run the loop should be 150 ms (as in the simple cfinclude).

Am I doing something wring here??

The code for all the files is attached. I would really appreciate if someone could throw a light into this. And any inputs on the performance overheads of using CFC's would be very welcome.

Thanks a lot,
SS

Attach Code

testCFC.cfm:

<cfset application.compTest = createObject("component","compTest")>
<cfset t1 = gettickcount()>
<cfset looptimes = application.compTest.doSomething()>
<!---cfinclude template="compTest.cfm"--->
<cfset timetaken = gettickcount() - t1>
<cfoutput>#timetaken#</cfoutput>
<cfoutput><br/>#looptimes#</cfoutput>

compTest.cfc:

<cfcomponent>
<cffunction name="doSomething">
<cfset looptick = gettickcount()>
<cfloop from="1" to="100000" index="i">
<cfset x = i*2 + 1>
</cfloop>
<cfset looptime = gettickcount() - looptick>
<cfreturn looptime>
</cffunction>
</cfcomponent>

compTest.cfm:

<cfloop from="1" to="100000" index="i">
<cfset x = i*2 + 1>
</cfloop>
348
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 01, 2008 Sep 01, 2008
LATEST
i think you need to var your variables inside the function otherwise they become part of the application scope which is not what you want.

So your cfc should look like this:

<cfcomponent>
<cffunction name="doSomething">
<cfset var i = "">
<cfset var x = "">
<cfset var looptick = "">
<cfset var looptime = "">

<cfset looptick = gettickcount()>
<cfloop from="1" to="100000" index="i">
<cfset x = i*2 + 1>
</cfloop>

<cfset looptime = gettickcount() - looptick>

<cfreturn looptime>
</cffunction>
</cfcomponent>

Run this again and see what it gives you.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources