Copy link to clipboard
Copied
I have a bunch of web apps that use <cfinvoke> statements to call CFCs. After a recent CF Server Admin class, our instructor mentioned that <cfinvoke> was VERY slow, and that I should be using CreateObject() instead, because it's more efficient.
So my question is, has anyone done any comparisons to see the actual difference? I'm curious to hear other people's experiences with this.
Copy link to clipboard
Copied
Incidentally... you know how people bang on about not being able to paste code into these forums? I had a bit of a problem getting test.cfm's code to paste in the: the forum seemed to want to try to put the code into a table, which munged it up somewhat.
It turned out it was due to the tabs I had WITHIN tags (eg: my attributes in my <cfparam> tags were vertically aligned for readability). If I took those out and only had leading tabs, then it pasted OK. I wonder if it's that sort of thing that causes other people grief?
--
Adam
Copy link to clipboard
Copied
Did your sodas stay safe, Dave?
They did!
Using BKBK's script, I got this:
createobject execution time: 30
cfinvoke execution time: 20
The CFC just did a select from a tiny database and cfdumped the results, so it's not much of a load.
This was CF9 and MySQL on Ubuntu 10.10 (my local machine).
cfinvoke seems to be faster, but perhaps it hogs more resources?
I would merely echo the things said by Adam and BKBK since then - build an independent test that doesn't involve other resources like a database, and test multiple iterations - and add one thing. To test something like this, you need to test it in parallel, not serially, as that's how people are going to run your applications. In other words, you need to do load testing to determine an absolute answer to a question like this.
That all said, Adam's test matched my anecdotal experience and my expectations - there really isn't much of a difference. Going back to your original question, I strongly suspect that your instructor's point was on instantiation of objects and how this can make a significant impact on performance, rather than just the question on its face about CFINVOKE vs createObject.
Dave Watts, CTO, Fig Leaf Software
Copy link to clipboard
Copied
Thanks for all the replies everyone. It was really helpful and interesting!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more