|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!
The recent trends like cloud computing, social, mobile and Internet of Things are forcing enterprises to modernize in order to compete in the competitive globalized markets. However, enterprises are approaching newer technologies with a more silo-ed way, gaining only sub optimal benefits. The Modern Enterprise model is presented as a newer way to think of enterprise IT, which takes a more holistic approach to embracing modern technologies.
May. 25, 2015 11:00 PM EDT Reads: 5,925
The true value of the Internet of Things (IoT) lies not just in the data, but through the services that protect the data, perform the analysis and present findings in a usable way. With many IoT elements rooted in traditional IT components, Big Data and IoT isn’t just a play for enterprise. In fact, the IoT presents SMBs with the prospect of launching entirely new activities and exploring innovative areas. CompTIA research identifies several areas where IoT is expected to have the greatest impact.
May. 25, 2015 09:00 PM EDT Reads: 4,757
Every day we read jaw-dropping stats on the explosion of data. We allocate significant resources to harness and better understand it. We build businesses around it. But we’ve only just begun. For big payoffs in Big Data, CIOs are turning to cognitive computing. Cognitive computing’s ability to securely extract insights, understand natural language, and get smarter each time it’s used is the next, logical step for Big Data.
May. 25, 2015 08:00 PM EDT Reads: 1,873
The 4th International Internet of @ThingsExpo, co-located with the 17th International Cloud Expo - to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA - announces that its Call for Papers is open. The Internet of Things (IoT) is the biggest idea since the creation of the Worldwide Web more than 20 years ago.
May. 25, 2015 07:00 PM EDT Reads: 1,523
There's no doubt that the Internet of Things is driving the next wave of innovation. Google has spent billions over the past few months vacuuming up companies that specialize in smart appliances and machine learning. Already, Philips light bulbs, Audi automobiles, and Samsung washers and dryers can communicate with and be controlled from mobile devices. To take advantage of the opportunities the Internet of Things brings to your business, you'll want to start preparing now.
May. 25, 2015 07:00 PM EDT Reads: 5,717
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo in Silicon Valley. 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 Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal an...
May. 25, 2015 04:00 PM EDT Reads: 2,437
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 ...
May. 25, 2015 03:00 PM EDT Reads: 4,213
The 17th International Cloud Expo has announced that its Call for Papers is open. 17th International Cloud Expo, to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, APM, APIs, Microservices, Security, Big Data, Internet of Things, DevOps 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 today!
May. 25, 2015 02:00 PM EDT Reads: 4,144
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...
May. 25, 2015 02:00 PM EDT Reads: 4,748
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. With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo, June 9-11, 2015, at the Javits Center in New York City. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be
May. 25, 2015 01:15 PM EDT Reads: 1,823
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...
May. 25, 2015 01:00 PM EDT Reads: 6,158
Container frameworks, such as Docker, provide a variety of benefits, including density of deployment across infrastructure, convenience for application developers to push updates with low operational hand-holding, and a fairly well-defined deployment workflow that can be orchestrated. Container frameworks also enable a DevOps approach to application development by cleanly separating concerns between operations and development teams. But running multi-container, multi-server apps with containers is very hard. You have to learn five new and different technologies and best practices (libswarm, sy...
May. 25, 2015 12:00 PM EDT Reads: 1,804
SYS-CON Events announced today that DragonGlass, an enterprise search platform, 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. After eleven years of designing and building custom applications, OpenCrowd has launched DragonGlass, a cloud-based platform that enables the development of search-based applications. These are a new breed of applications that utilize a search index as their backbone for data retrieval. They can easily adapt to new data sets and provide access to both structured and unstruc...
May. 25, 2015 12:00 PM EDT Reads: 1,750
There's Big Data, then there's really Big Data from the Internet of Things. IoT is evolving to include many data possibilities like new types of event, log and network data. The volumes are enormous, generating tens of billions of logs per day, which raise data challenges. Early IoT deployments are relying heavily on both the cloud and managed service providers to navigate these challenges. In her session at Big Data Expo®, Hannah Smalltree, Director at Treasure Data, discussed how IoT, Big Data and deployments are processing massive data volumes from wearables, utilities and other machines...
May. 25, 2015 10:00 AM EDT Reads: 4,056
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 will peel 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 environment, and we must architect and code accordingly. At the very least, you'll have no problem fil...
May. 25, 2015 10:00 AM EDT Reads: 1,737
SYS-CON Events announced today that MetraTech, now part of Ericsson, 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. Ericsson is the driving force behind the Networked Society- a world leader in communications infrastructure, software and services. Some 40% of the world’s mobile traffic runs through networks Ericsson has supplied, serving more than 2.5 billion subscribers.
May. 25, 2015 09:45 AM EDT Reads: 1,088
The worldwide cellular network will be the backbone of the future IoT, and the telecom industry is clamoring to get on board as more than just a data pipe. In his session at @ThingsExpo, Evan McGee, CTO of Ring Plus, Inc., discussed what service operators can offer that would benefit IoT entrepreneurs, inventors, and consumers. Evan McGee is the CTO of RingPlus, a leading innovative U.S. MVNO and wireless enabler. His focus is on combining web technologies with traditional telecom to create a new breed of unified communication that is easily accessible to the general consumer. With over a de...
May. 25, 2015 06:00 AM EDT Reads: 4,658
Disruptive macro trends in technology are impacting and dramatically changing the "art of the possible" relative to supply chain management practices through the innovative use of IoT, cloud, machine learning and Big Data to enable connected ecosystems of engagement. Enterprise informatics can now move beyond point solutions that merely monitor the past and implement integrated enterprise fabrics that enable end-to-end supply chain visibility to improve customer service delivery and optimize supplier management. Learn about enterprise architecture strategies for designing connected systems tha...
May. 25, 2015 05:00 AM EDT Reads: 5,833
Cloud is not a commodity. And no matter what you call it, computing doesn’t come out of the sky. It comes from physical hardware inside brick and mortar facilities connected by hundreds of miles of networking cable. And no two clouds are built the same way. SoftLayer gives you the highest performing cloud infrastructure available. One platform that takes data centers around the world that are full of the widest range of cloud computing options, and then integrates and automates everything. Join SoftLayer on June 9 at 16th Cloud Expo to learn about IBM Cloud's SoftLayer platform, explore se...
May. 25, 2015 04:45 AM EDT Reads: 3,059
SYS-CON Media announced today that 9 out of 10 " most read" DevOps articles are published by @DevOpsSummit Blog. Launched in October 2014, @DevOpsSummit Blog offers top articles, news stories, and blog posts from the world's well-known experts and guarantees better exposure for its authors than any other publication. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait for long development cycles that produce softw...
May. 25, 2015 04:15 AM EDT Reads: 4,036