Running Performance Metrics on ColdFusion Functions and Operators

By davidjmedlock
We teamed up with SiteGround
To bring you up to 65% off web hosting, plus free access to the entire SitePoint Premium library (worth $99). Get SiteGround + SitePoint Premium Now

…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:


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:


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: – CFSCRIPT performance – CFIF performance

Download the Excel spreadsheet with performance data

The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
We teamed up with SiteGround
To bring you up to 65% off web hosting, plus free access to the entire SitePoint Premium library (worth $99). Get SiteGround + SitePoint Premium Now
Login or Create Account to Comment
Login Create Account