Created
June 13, 2014 17:56
-
-
Save JamoCA/a45e46ccf2fad4ca18d5 to your computer and use it in GitHub Desktop.
Sample ColdFusion code to compare response times of ColdFusion CFHTTP against HTTPRequestCFC & CFX_HTTP5.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
CFHTTP https://wikidocs.adobe.com/wiki/display/coldfusionen/cfhttp | |
HTTPRequestCF http://coldfusion9.blogspot.com/2012/03/custom-cfhttp-tag.html | |
CFX_HTTP5 http://www.cftagstore.com/tags/cfxhttp5.cfm | |
Here are the results that I received: | |
ColdFusion 10 CFHTTP: 9.04 CFC: 18.14 CFX_HTTP5: 1.26 | |
ColdFusion 9 CFHTTP: 8.08 CFC: 158.92 CFX_HTTP5: 2.4 | |
ColdFusion 8 CFHTTP: 4.86 CFC: 149.14 CFX_HTTP5: 2.14 | |
---> | |
<cfset assets = arraynew(1)> | |
<cfloop from="1" to="10" index="thisAsset"> | |
<cfset arrayappend(assets, "http://YOURSERVER1.com/static_file.png")> | |
<cfset arrayappend(assets, "http://YOURSERVER2.com/static_file.jpg")> | |
<cfset arrayappend(assets, "http://YOURSERVER3.com/static_file.pdf")> | |
<cfset arrayappend(assets, "http://YOURSERVER4.com/static_file.gif")> | |
<cfset arrayappend(assets, "http://YOURSERVER5.com/static_file.bmp")> | |
</cfloop> | |
<cfoutput> | |
<h1>CFHTTP performance testing</h1> | |
<p>Calling cfhttp #arraylen(assets)# times</p> | |
</cfoutput> | |
<!--- Collect service data ---> | |
<cfset Results = ArrayNew(1)> | |
<cfloop array="#assets#" index="thisAsset"> | |
<cfset ThisTiming = structnew()> | |
<cfset ThisTiming["ResourceURL"] = thisAsset> | |
<cfset ThisTiming["CF"] = structnew()> | |
<cfset ThisTiming["CFX"] = structnew()> | |
<cfset ThisTiming["CFC"] = structnew()> | |
<cftry> | |
<cfset start = gettickcount()> | |
<cfhttp method="get" url="#thisAsset#"> | |
<cfset ThisTiming["CF"]["Duration"] = gettickcount() - start> | |
<cfset ThisTiming["CF"]["Status"] = val(cfhttp.statuscode)> | |
<cfcatch> | |
<cfset ThisTiming["CF"]["Status"] = "FAIL"> | |
</cfcatch> | |
</cftry> | |
<cftry> | |
<cfset start = gettickcount()> | |
<CFX_HTTP5 URL="#thisAsset#" METHOD="get"> | |
<CFSET ThisTiming["CFX"]["Duration"] = gettickcount() - start> | |
<CFSET ThisTiming["CFX"]["Status"] = val(HTTPSTATUS)> | |
<cfcatch> | |
<CFSET ThisTiming["CFX"]["Status"] = "FAIL"> | |
</cfcatch> | |
</cftry> | |
<cftry> | |
<cfset start = gettickcount()> | |
<cfinvoke component="httprequest" method="init" returnvariable="objectHTTP"> | |
<cfinvokeargument name="pass_url" value="#ThisAsset#"><!--- | |
<cfinvokeargument name="pass_variables" value="#PassIn#"> | |
<cfinvokeargument name="pass_httpuseragent" value=""> | |
<cfinvokeargument name="pass_httphost" value=""> | |
<cfinvokeargument name="pass_httpport" value=""> | |
<cfinvokeargument name="pass_debug" value="false"> | |
<cfinvokeargument name="pass_autoredirect" value="true"> | |
<cfinvokeargument name="pass_remember_cookie" value=""> ---> | |
</cfinvoke> | |
<cfset ThisTiming["CFC"]["Duration"] = gettickcount() - start> | |
<cfset ThisTiming["CFC"]["Status"] = val(objectHTTP.Status)> | |
<cfcatch> | |
<cfset ThisTiming["CFC"]["Status"] = "FAIL"> | |
</cfcatch> | |
</cftry> | |
<cfset arrayappend(results, ThisTiming)> | |
</cfloop> | |
<!--- Consolidate Results ---> | |
<cfset Final = structnew()> | |
<cfloop list="CF,CFX,CFC" index="thisType"> | |
<cfset Final[thisType] = structnew()> | |
<cfset Final[thisType]["Data"] = arraynew(1)> | |
<cfset Final[thisType]["Total"] = -1> | |
<cfset Final[thisType]["Average"] = -1> | |
<cfset Final[thisType]["Min"] = -1> | |
<cfset Final[thisType]["Max"] = -1> | |
<cfset Final[thisType]["Results"] = 0> | |
<cfloop array="#Results#" index="thisResult"> | |
<cfif val(thisResult[thisType].status) IS 200> | |
<cfset arrayappend(Final[thisType]["Data"], val(thisResult[thisType].Duration))> | |
</cfif> | |
</cfloop> | |
<cfif arraylen(Final[thisType]["Data"])> | |
<cfset Final[thisType]["Results"] = arraylen(Final[thisType]["Data"])> | |
<cfset Final[thisType]["Total"] = arraysum(Final[thisType]["Data"])> | |
<cfset Final[thisType]["Average"] = Final[thisType]["Total"] / Final[thisType]["Results"]> | |
<cfset Final[thisType]["Min"] = arraymin(Final[thisType]["Data"])> | |
<cfset Final[thisType]["Max"] = arraymax(Final[thisType]["Data"])> | |
</cfif> | |
</cfloop> | |
<h2>Results</h2> | |
<cfdump var="#Final#" label="#arraylen(Results)# Test (Summary)"> | |
<cfdump var="#Results#" expand="no" label="#arraylen(Results)# Test (Data)"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment