|By Ben Forta||
|January 31, 2003 12:00 AM EST||
Which is faster, <CFQUERY> or <CFLOOP>? Which is faster, CFML or <CFSCRIPT>? Which is faster... ? If you're a ColdFusion developer, chances are that you've asked (or have been asked) these questions and others like them.
So, Which Is Faster?
Okay, so which option is actually the faster one? Honestly? I'm not so sure. Once upon a time (pre-CF4) we were told that <CFLOOP> was very slow. Then (when CF4 shipped) we were told that <CFLOOP> had been optimized and outperformed <CFOUTPUT>. And now, well, CFMX changes everything. So, which is faster?
Of course, performance-related questions are legitimate. We all keep looking for ways to tweak just a little more oomph from our code. But the truth is that this is not just a CFML syntax concern; this affects all sorts of code, database calls, design considerations, reuse implementations, and more.
ColdFusion debugging helps us out a little here. Execution time (for a complete page or parts thereof) provides an invaluable peek under the CF covers. But for more granular performance comparisons, for detailed benchmarking, and for ascertaining definitive performance data, debug output falls a bit short.
Enter ColdFusion MX
Ever since ColdFusion MX shipped I've been trying to better understand exactly what the product is doing internally so as to be able to write better code. And like many of you, I've discovered that an interesting side effect of ColdFusion's new processing engine is that many of the tips and tricks I lived by don't really apply anymore; some have negligible effects on my code, and others are just plain wrong. So I created an application, a really simple performance comparison tool, using good old ColdFusion. This tool has proven so invaluable that I feel compelled to share it with you. Read on.
Measuring Execution Time
The key to measuring any execution time in ColdFusion is an intriguing little function named GetTickCount(). GetTickCount() takes no parameters, and returns a number that is, in and of itself, rather useless. So what makes GetTickCount() so intriguing? The number that GetTickCount() returns is a value in milliseconds, and invoking GetTickCount() exactly one second after a prior GetTickCount() invocation returns a value exactly 1000 times greater than the first returned value.
In other words, to determine exactly how long a line of code takes to execute, you could do the following:
... some CFML code ...
Measuring a single execution yields no usable data - a single invocation may run faster or slower at any time based on lots of other factors (ColdFusion factors and otherwise). To really measure execution time, code must be executed repeatedly, and each iteration must be measured individually and stored. Then an average execution time can be determined by processing all of the saved values.
The simplest way to do this in ColdFusion is to loop through the iterations, saving each measurement to an array, perhaps like this:
...some CFML code...
<CFSET ArrayAppend(timings, end-start)>
Then to obtain the average execution time you could simply use:
Similarly, total execution time, slowest iteration, and fastest iteration could easily be determined using array functions like this:
To compare the processing of two options you'd simply repeat this process twice (saving the data to two arrays, one for each option), and then compare the results.
Detailed benchmarking data is useless unless it can be presented in a format that makes it clear and understandable. <CFCHART> (and related tags) makes it easy to plot the data in a highly usable and readable format.
<CFCHART> is usually used to chart database query results, but as this code snippet demonstrates, individual data points can be passed explicitly using the <CFCHARTDATA> tag. In this example, two arrays (named timings1 and timings2) are being charted in individual data series in a single chart. The inner loops loop from 1-100, and on each iteration, passes the appropriate array value (from both arrays) to <CFCHART>.
<!--- Graph it --->
Putting It All Together
SERIESLABEL="Option 1 Title"
<CFLOOP FROM="1" TO="100" INDEX="i">
SERIESLABEL="Option 2 Title"
<CFLOOP FROM="1" TO="100" INDEX="i">
Over the past few months I've found myself using code much like what I described above over and over. So to make testing quicker and cleaner, I created the "Which is Faster?" application. The app is actually incredibly simple; the idea is as follows:
For my own testing (to test <CFLOOP> versus <CFOUTPUT>) I used three files. Here they are:
ORDER BY LastName, FirstName
These are simple, crude, and not real-world at all. But they are perfect for this type of testing - you wouldn't want lots of other processing included, as that could skew the results.
FORM.CFM (Listing 1) contains the code for the form, a simple HTML form as described above (see Figure 1). One checkbox worth noting is the "Exclude first iteration" option; as ColdFusion may have to compile the code on the first execution, you may not want to include that in the collected data (as it will skew the results, creating a much slower first value).
PROCESS.CFM (Listing 2) processes the form. The code first uses <CFPARAM> and a series of <CFIF> statements to validate and prepare passed values. If a preprocessor file was specified, it is then executed. Next, if the "Exclude first iteration" option was checked, each included file is executed once (using <CFINCLUDE> tags) so as to force a compile if needed. Then comes the test itself; <CFLOOP> loops from 1 to the specified number of iterations and, within each iteration, both files are executed and the timings for each appended to one of two arrays (one for each test). Finally the results are displayed in five graphs (see Figure 2). The first shows the execution details, and the next four show total processing time, average iteration processing time, as well as fastest and slowest iteration processing time. (In case you were wondering why I used two arrays instead of a single two-dimensional array, these last four graphs are the reason; functions like ArraySum() and ArrayAvg() work on single dimensional arrays only).
Where to Go from Here
Of course, writing all this down has gotten me thinking. It would be nice if instead of just including files with <CFINCLUDE> the application would give you a choice and also allow:
- <CFHTTP> calls to complete pages, local or remote
- <CFINVOKE> calls to Web services or ColdFusion Components
- <CFMODULE> calls to Custom Tags
So, which is faster, <CFLOOP> or <CFOUTPUT>? Answer: <CFLOOP> seems slightly faster, but there is so little difference it's essentially insignificant. Which is faster, CFML or <CFSCRIPT>? Answer: almost no difference (unless I ran ridiculously large tests, as in 10,000 assignments per iteration). Which is faster? Now you can find out yourself - and not just with CFML language elements, but whole blocks of functionality, pages, SQL statements, and more. Enjoy!
|ramaa rajan 12/03/03 11:09:27 AM EST|
I would like to capture the execution time of each page as it displayed in the browser. GetTickCount() function gives a slightly different result. Can you pls tell me how. Thanks a lot
|07/24/03 12:51:00 PM EDT|
P2P RTC will impact the landscape of communications, shifting from traditional telephony style communications models to OTT (Over-The-Top) cloud assisted & PaaS (Platform as a Service) communication services. The P2P shift will impact many areas of our lives, from mobile communication, human interactive web services, RTC and telephony infrastructure, user federation, security and privacy implications, business costs, and scalability. In his session at @ThingsExpo, Robin Raymond, Chief Architect at Hookflash, will walk through the shifting landscape of traditional telephone and voice services ...
Nov. 24, 2014 05:00 PM EST Reads: 654
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at Internet of @ThingsExpo, James Kirkland, Chief Architect for the Internet of Things and Intelligent Systems at Red Hat, described how to revolutioniz...
Nov. 24, 2014 03:00 PM EST Reads: 1,453
Bit6 today issued a challenge to the technology community implementing Web Real Time Communication (WebRTC). To leap beyond WebRTC’s significant limitations and fully leverage its underlying value to accelerate innovation, application developers need to consider the entire communications ecosystem.
Nov. 24, 2014 12:00 PM EST Reads: 1,354
The definition of IoT is not new, in fact it’s been around for over a decade. What has changed is the public's awareness that the technology we use on a daily basis has caught up on the vision of an always on, always connected world. If you look into the details of what comprises the IoT, you’ll see that it includes everything from cloud computing, Big Data analytics, “Things,” Web communication, applications, network, storage, etc. It is essentially including everything connected online from hardware to software, or as we like to say, it’s an Internet of many different things. The difference ...
Nov. 24, 2014 11:00 AM EST Reads: 1,468
Cloud Expo 2014 TV commercials will feature @ThingsExpo, which was launched in June, 2014 at New York City's Javits Center as the largest 'Internet of Things' event in the world.
Nov. 24, 2014 09:00 AM EST Reads: 1,507
SYS-CON Events announced today that Windstream, a leading provider of advanced network and cloud communications, has been named “Silver Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9–11, 2015, at the Javits Center in New York, NY. Windstream (Nasdaq: WIN), a FORTUNE 500 and S&P 500 company, is a leading provider of advanced network communications, including cloud computing and managed services, to businesses nationwide. The company also offers broadband, phone and digital TV services to consumers primarily in rural areas.
Nov. 23, 2014 07:30 PM EST Reads: 1,722
"There is a natural synchronization between the business models, the IoT is there to support ,” explained Brendan O'Brien, Co-founder and Chief Architect of Aria Systems, in this SYS-CON.tv interview at the 15th International Cloud Expo®, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
Nov. 23, 2014 12:00 PM EST Reads: 1,654
The major cloud platforms defy a simple, side-by-side analysis. Each of the major IaaS public-cloud platforms offers their own unique strengths and functionality. Options for on-site private cloud are diverse as well, and must be designed and deployed while taking existing legacy architecture and infrastructure into account. Then the reality is that most enterprises are embarking on a hybrid cloud strategy and programs. In this Power Panel at 15th Cloud Expo (http://www.CloudComputingExpo.com), moderated by Ashar Baig, Research Director, Cloud, at Gigaom Research, Nate Gordon, Director of T...
Nov. 23, 2014 07:45 AM EST Reads: 1,622
ARMONK, N.Y., Nov. 20, 2014 /PRNewswire/ -- IBM (NYSE: IBM) today announced that it is bringing a greater level of control, security and flexibility to cloud-based application development and delivery with a single-tenant version of Bluemix, IBM's platform-as-a-service. The new platform enables developers to build ap...
Nov. 22, 2014 05:30 PM EST Reads: 1,485
An entirely new security model is needed for the Internet of Things, or is it? Can we save some old and tested controls for this new and different environment? In his session at @ThingsExpo, New York's at the Javits Center, Davi Ottenheimer, EMC Senior Director of Trust, reviewed hands-on lessons with IoT devices and reveal a new risk balance you might not expect. Davi Ottenheimer, EMC Senior Director of Trust, has more than nineteen years' experience managing global security operations and assessments, including a decade of leading incident response and digital forensics. He is co-author of t...
Nov. 22, 2014 05:30 PM EST Reads: 1,363
Technology is enabling a new approach to collecting and using data. This approach, commonly referred to as the "Internet of Things" (IoT), enables businesses to use real-time data from all sorts of things including machines, devices and sensors to make better decisions, improve customer service, and lower the risk in the creation of new revenue opportunities. In his General Session at Internet of @ThingsExpo, Dave Wagstaff, Vice President and Chief Architect at BSQUARE Corporation, discuss the real benefits to focus on, how to understand the requirements of a successful solution, the flow of ...
Nov. 21, 2014 08:00 PM EST Reads: 1,474
The security devil is always in the details of the attack: the ones you've endured, the ones you prepare yourself to fend off, and the ones that, you fear, will catch you completely unaware and defenseless. The Internet of Things (IoT) is nothing if not an endless proliferation of details. It's the vision of a world in which continuous Internet connectivity and addressability is embedded into a growing range of human artifacts, into the natural world, and even into our smartphones, appliances, and physical persons. In the IoT vision, every new "thing" - sensor, actuator, data source, data con...
Nov. 21, 2014 08:00 PM EST Reads: 1,420
"BSQUARE is in the business of selling software solutions for smart connected devices. It's obvious that IoT has moved from being a technology to being a fundamental part of business, and in the last 18 months people have said let's figure out how to do it and let's put some focus on it, " explained Dave Wagstaff, VP & Chief Architect, at BSQUARE Corporation, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
Nov. 21, 2014 07:00 PM EST Reads: 1,334
Focused on this fast-growing market’s needs, Vitesse Semiconductor Corporation (Nasdaq: VTSS), a leading provider of IC solutions to advance "Ethernet Everywhere" in Carrier, Enterprise and Internet of Things (IoT) networks, introduced its IStaX™ software (VSC6815SDK), a robust protocol stack to simplify deployment and management of Industrial-IoT network applications such as Industrial Ethernet switching, surveillance, video distribution, LCD signage, intelligent sensors, and metering equipment. Leveraging technologies proven in the Carrier and Enterprise markets, IStaX is designed to work ac...
Nov. 20, 2014 09:15 PM EST Reads: 1,402
C-Labs LLC, a leading provider of remote and mobile access for the Internet of Things (IoT), announced the appointment of John Traynor to the position of chief operating officer. Previously a strategic advisor to the firm, Mr. Traynor will now oversee sales, marketing, finance, and operations. Mr. Traynor is based out of the C-Labs office in Redmond, Washington. He reports to Chris Muench, Chief Executive Officer. Mr. Traynor brings valuable business leadership and technology industry expertise to C-Labs. With over 30 years' experience in the high-tech sector, John Traynor has held numerous...
Nov. 20, 2014 06:00 PM EST Reads: 1,356
The 3rd International @ThingsExpo, co-located with the 16th International Cloud Expo - to be held June 9-11, 2015, at the Javits Center in New York City, NY - announces that it is now accepting Keynote Proposals. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devices - computers, smartphones, tablets, and sensors - connected to the Internet by 2020. This number will continue to grow at a rapid pace for the next several decades.
Nov. 20, 2014 01:00 PM EST Reads: 1,605
The Internet of Things is not new. Historically, smart businesses have used its basic concept of leveraging data to drive better decision making and have capitalized on those insights to realize additional revenue opportunities. So, what has changed to make the Internet of Things one of the hottest topics in tech? In his session at @ThingsExpo, Chris Gray, Director, Embedded and Internet of Things, discussed the underlying factors that are driving the economics of intelligent systems. Discover how hardware commoditization, the ubiquitous nature of connectivity, and the emergence of Big Data a...
Nov. 20, 2014 12:30 PM EST Reads: 1,813
Almost everyone sees the potential of Internet of Things but how can businesses truly unlock that potential. The key will be in the ability to discover business insight in the midst of an ocean of Big Data generated from billions of embedded devices via Systems of Discover. Businesses will also need to ensure that they can sustain that insight by leveraging the cloud for global reach, scale and elasticity.
Nov. 18, 2014 09:00 PM EST Reads: 2,032
SYS-CON Events announced today that IDenticard will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. IDenticard™ is the security division of Brady Corp (NYSE: BRC), a $1.5 billion manufacturer of identification products. We have small-company values with the strength and stability of a major corporation. IDenticard offers local sales, support and service to our customers across the United States and Canada. Our partner network encompasses some 300 of the world's leading systems integrators and security s...
Nov. 18, 2014 08:15 PM EST Reads: 1,593
IoT is still a vague buzzword for many people. In his session at @ThingsExpo, Mike Kavis, Vice President & Principal Cloud Architect at Cloud Technology Partners, discussed the business value of IoT that goes far beyond the general public's perception that IoT is all about wearables and home consumer services. He also discussed how IoT is perceived by investors and how venture capitalist access this space. Other topics discussed were barriers to success, what is new, what is old, and what the future may hold. Mike Kavis is Vice President & Principal Cloud Architect at Cloud Technology Pa...
Nov. 18, 2014 01:30 PM EST Reads: 2,020