Running Performance Metrics on ColdFusion Functions and Operators

Share this article

…posted by davidjmedlock:

Have you ever noticed developers making statements about how well various operators and functions perform when compared with other functions and operators? For example, how well does perform when compared to ? Is there really a significant difference?

Well, in my recent article on queries, I used a block of code that output the columns in a query in a table and then output the values below that. In that query I used the Evaluate() function to display the values of the columns. One eagle-eyed reader pointed out to me that using array notation is preferable to the Evaluate function and that Evaluate should be avoided in any situation if at all possible. Here’s the code block I used:






#column#
#Evaluate(column)#

The suggestion was that instead of using Evaluate(column), I should have used GetUsers

. Now, I’d like to say a couple of things here. First of all, this was a simple demonstration and using Evaluate(column) versus GetUsers
is not going to make any performance difference whatsoever when displaying a small amount of data. It’s merely personal preference.

Now, I’m not offended by any remarks such as this at all. I enjoy seeing how other people code their applications and, hey, if it speeds up my app to use a different method, I’m all ears! But sometimes developers take things to extremes. I decided to do some research to find out if useing Evaluate(column) really was faster than GetUsers

. I set up a very simple experiment to test this.

This experiment was not entirely comprehensive and I invite everyone to try this experiment out (on a development machine, NOT a live server!) to with different variables to see what results you get.

First, here is the code I used:


// this simply sets up the testing query
qry = QueryNew("col1,col2");
for (i = 1; i lte 10; i = i + 1) {
QueryAddRow(qry, 1);
QuerySetCell(qry, "col1", i * 2, qry.RecordCount);
QuerySetCell(qry, "col2", i * 3, qry.RecordCount);
}
















Entire Process Time: #endTest# (ms)
Total Looping Time: #TotalTime# (ms)
Average Looping Time: #AvgTime#

I created a query that was 2 columns by 10 rows. I then looped over the query 20,000 times. Inside the query loop, I looped over the qry.ColumnList variable and set a variable called temp to the value of the current column in the current row.

Notice that I ran this test 20 different times and then I changed the:



to:



and then ran it another 20 times. I recorded the total amount of time it took for the 20,000 iterations, the average time for each iteration, and the total time it took to process the entire page. All times are in millseconds. To make a long story a little bit shorter, the average evaluation time using the array notation was .231 milliseconds. (Yes, that’s a very small number.) The average evaluation time using Evaluate() was .228 milliseconds. That’s an even smaller number. If you look at the data, all the numbers using Evaluate() were smaller. All the other code remained exactly the same.

I did not restart my server in between these tests, which may have altered the results a bit due to recompiling and initializing everything. I doubt it would have has a huge effect on the results, though. And in a live environment, you don’t restart the server every time you run a report or load a form, etc.

I’m going to run some more tests at a later point in time to see what results I get. I’ll increase the iterations to 100,000 and run it 50 times. (When I get the time for that… It will probably take a good 45 seconds or so to run each time.)

I guess my point here is that for a small to medium sized application, using Evaluate() is not going to cause a huge bottleneck in your system. Yes, there are usually other ways around it and if you don’t like using it, then find another way around it. And this is only one scenario using the Evaluate() function. There are countless others and in other situations Evaluate() may not perform well at all.

Here are a few links about CF performance you may find interesting:

http://www.markme.com/cantrell/archives/003088.cfm – CFSCRIPT performance

http://www.findarticles.com/cf_dls/m0MLU/11_4/94550933/p1/article.jhtml – CFIF performance

Download the Excel spreadsheet with performance data

davidjmedlockdavidjmedlock
View Author
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week