|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|
The Internet of Things can drive efficiency for airlines and airports. In their session at @ThingsExpo, Shyam Varan Nath, Principal Architect with GE, and Sudip Majumder, senior director of development at Oracle, discussed the technical details of the connected airline baggage and related social media solutions. These IoT applications will enhance travelers' journey experience and drive efficiency for the airlines and the airports.
Jan. 20, 2017 05:45 PM EST Reads: 2,085
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo 2016 in New York. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place June 6-8, 2017, at the Javits Center in New York City, New York, is co-located with 20th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry p...
Jan. 20, 2017 05:15 PM EST Reads: 3,801
"LinearHub provides smart video conferencing, which is the Roundee service, and we archive all the video conferences and we also provide the transcript," stated Sunghyuk Kim, CEO of LinearHub, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA.
Jan. 20, 2017 03:00 PM EST Reads: 1,641
Things are changing so quickly in IoT that it would take a wizard to predict which ecosystem will gain the most traction. In order for IoT to reach its potential, smart devices must be able to work together. Today, there are a slew of interoperability standards being promoted by big names to make this happen: HomeKit, Brillo and Alljoyn. In his session at @ThingsExpo, Adam Justice, vice president and general manager of Grid Connect, will review what happens when smart devices don’t work togethe...
Jan. 20, 2017 02:15 PM EST Reads: 605
"There's a growing demand from users for things to be faster. When you think about all the transactions or interactions users will have with your product and everything that is between those transactions and interactions - what drives us at Catchpoint Systems is the idea to measure that and to analyze it," explained Leo Vasiliou, Director of Web Performance Engineering at Catchpoint Systems, in this SYS-CON.tv interview at 18th Cloud Expo, held June 7-9, 2016, at the Javits Center in New York Ci...
Jan. 20, 2017 01:30 PM EST Reads: 5,729
The 20th International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held June 6-8, 2017, at the Javits Center in New York City, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Containers, Microservices and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal ...
Jan. 20, 2017 01:30 PM EST Reads: 5,233
Discover top technologies and tools all under one roof at April 24–28, 2017, at the Westin San Diego in San Diego, CA. Explore the Mobile Dev + Test and IoT Dev + Test Expo and enjoy all of these unique opportunities: The latest solutions, technologies, and tools in mobile or IoT software development and testing. Meet one-on-one with representatives from some of today's most innovative organizations
Jan. 20, 2017 12:30 PM EST Reads: 1,650
20th Cloud Expo, taking place June 6-8, 2017, at the Javits Center in New York City, NY, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy.
Jan. 20, 2017 12:30 PM EST Reads: 4,345
WebRTC is the future of browser-to-browser communications, and continues to make inroads into the traditional, difficult, plug-in web communications world. The 6th WebRTC Summit continues our tradition of delivering the latest and greatest presentations within the world of WebRTC. Topics include voice calling, video chat, P2P file sharing, and use cases that have already leveraged the power and convenience of WebRTC.
Jan. 20, 2017 12:30 PM EST Reads: 3,186
SYS-CON Events announced today that Super Micro Computer, Inc., a global leader in Embedded and IoT solutions, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 7-9, 2017, at the Javits Center in New York City, NY. Supermicro (NASDAQ: SMCI), the leading innovator in high-performance, high-efficiency server technology, is a premier provider of advanced server Building Block Solutions® for Data Center, Cloud Computing, Enterprise IT, Hadoop/Big Data, HPC and E...
Jan. 20, 2017 12:15 PM EST Reads: 5,836
Internet of @ThingsExpo, taking place June 6-8, 2017 at the Javits Center in New York City, New York, is co-located with the 20th International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. @ThingsExpo New York Call for Papers is now open.
Jan. 20, 2017 10:45 AM EST Reads: 3,701
WebRTC sits at the intersection between VoIP and the Web. As such, it poses some interesting challenges for those developing services on top of it, but also for those who need to test and monitor these services. In his session at WebRTC Summit, Tsahi Levent-Levi, co-founder of testRTC, reviewed the various challenges posed by WebRTC when it comes to testing and monitoring and on ways to overcome them.
Jan. 20, 2017 10:45 AM EST Reads: 6,089
DevOps is being widely accepted (if not fully adopted) as essential in enterprise IT. But as Enterprise DevOps gains maturity, expands scope, and increases velocity, the need for data-driven decisions across teams becomes more acute. DevOps teams in any modern business must wrangle the ‘digital exhaust’ from the delivery toolchain, "pervasive" and "cognitive" computing, APIs and services, mobile devices and applications, the Internet of Things, and now even blockchain. In this power panel at @...
Jan. 20, 2017 09:45 AM EST Reads: 2,933
WebRTC services have already permeated corporate communications in the form of videoconferencing solutions. However, WebRTC has the potential of going beyond and catalyzing a new class of services providing more than calls with capabilities such as mass-scale real-time media broadcasting, enriched and augmented video, person-to-machine and machine-to-machine communications. In his session at @ThingsExpo, Luis Lopez, CEO of Kurento, introduced the technologies required for implementing these idea...
Jan. 20, 2017 08:30 AM EST Reads: 4,761
Buzzword alert: Microservices and IoT at a DevOps conference? What could possibly go wrong? In this Power Panel at DevOps Summit, moderated by Jason Bloomberg, the leading expert on architecting agility for the enterprise and president of Intellyx, panelists peeled away the buzz and discuss the important architectural principles behind implementing IoT solutions for the enterprise. As remote IoT devices and sensors become increasingly intelligent, they become part of our distributed cloud enviro...
Jan. 20, 2017 08:15 AM EST Reads: 4,955
"A lot of times people will come to us and have a very diverse set of requirements or very customized need and we'll help them to implement it in a fashion that you can't just buy off of the shelf," explained Nick Rose, CTO of Enzu, in this SYS-CON.tv interview at 18th Cloud Expo, held June 7-9, 2016, at the Javits Center in New York City, NY.
Jan. 20, 2017 08:15 AM EST Reads: 4,720
The WebRTC Summit New York, to be held June 6-8, 2017, at the Javits Center in New York City, NY, announces that its Call for Papers is now open. Topics include all aspects of improving IT delivery by eliminating waste through automated business models leveraging cloud technologies. WebRTC Summit is co-located with 20th International Cloud Expo and @ThingsExpo. WebRTC is the future of browser-to-browser communications, and continues to make inroads into the traditional, difficult, plug-in web co...
Jan. 20, 2017 07:15 AM EST Reads: 2,982
In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
Jan. 20, 2017 07:00 AM EST Reads: 9,083
For basic one-to-one voice or video calling solutions, WebRTC has proven to be a very powerful technology. Although WebRTC’s core functionality is to provide secure, real-time p2p media streaming, leveraging native platform features and server-side components brings up new communication capabilities for web and native mobile applications, allowing for advanced multi-user use cases such as video broadcasting, conferencing, and media recording.
Jan. 20, 2017 07:00 AM EST Reads: 6,875
Web Real-Time Communication APIs have quickly revolutionized what browsers are capable of. In addition to video and audio streams, we can now bi-directionally send arbitrary data over WebRTC's PeerConnection Data Channels. With the advent of Progressive Web Apps and new hardware APIs such as WebBluetooh and WebUSB, we can finally enable users to stitch together the Internet of Things directly from their browsers while communicating privately and securely in a decentralized way.
Jan. 20, 2017 03:00 AM EST Reads: 928