Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Created August 3, 2013 16:32
Show Gist options
  • Save adamcameron/6147055 to your computer and use it in GitHub Desktop.
Save adamcameron/6147055 to your computer and use it in GitHub Desktop.
Some code to generate unique CFCs for benchmarking CFC-loading when ColdFusion either saves class files, or does not.
<cfoutput>
<#cf#component output="false">
<#cf#function name="init" returntype="#componentReturnType#" access="public" output="false" hint="Initialises and returns the object">
<#cf#argument name="configFile" type="string" required="true" hint="Config file name">
<#cf#set var jsonConfig = "">
<#cf#file action="read" file="##expandPath('./')####arguments.configFile##" variable="rawConfig">
<#cf#set variables.config = deserializeJson(jsonConfig)>
<#cf#return this>
</#cf#function>
#functions#
</#cf#component>
</cfoutput>
<cfoutput>
<#cf#function name="f#createBareUuid()#" returntype="string" output="false" hint="A unique function">
<#cf#argument name="data" type="query" required="true" hint="Data to process">
<#cf#argument name="col" type="string" required="true" hint="Column to filter">
<#cf#set var resultData = false>
<#cf#set var filterValue = "#createUuid()#">
<#cf#set var result = "">
<#cf#query name="resultData" dbtype="query">
SELECT *
FROM arguments.data
WHERE ##col## = <#cf#queryparam value="##filterValue##" cfsqltype="CF_SQL_VARCHAR">
</#cf#query>
<#cf#loop query="resultData">
<#cf#if len(otherCol) GT #randRange(1,10)#>
<#cf#set result = listAppend(result, otherCol)>
</#cf#if>
</#cf#loop>
<#cf#return result>
</#cf#function></cfoutput>
<cfflush interval="16">
<cfscript>
param name="URL.iterations" type="integer" default=0;
cf = "cf";
for (x=1; x <= URL.iterations; x++){
functions = "";
functionCount = randRange(5,15);
for(i=1; i <= functionCount; i++){
savecontent variable="code" {
include "functionTemplate.cfm";
}
functions &= code;
}
componentReturnType = "Component#createBareUuid()#";
savecontent variable="code" {
include "componentTemplate.cfm";
}
fileWrite(expandPath("./api/") & componentReturnType & ".cfc", code);
o = createObject("api.#componentReturnType#");
writeOutput("#x#/#URL.iterations# #componentReturnType#.cfc written and tested<br>");
}
writeOutput("Created #iterations# files<br>");
string function createBareUuid() {
return replace(createUuid(), "-", "", "all");
}
</cfscript>
<cfflush interval="16">
<cfscript>
files = directoryList(expandPath("./api"), false);
filesLen = arrayLen(files);
start = getTickCount();
for (i=1; i <= filesLen; i++){
fileName = listLast(files[i], "\");
cfcName = listFirst(fileName, ".");
o = createObject("api.#cfcName#");
writeOutput("#i#/#filesLen# #getMetadata(o).fullName#<br>");
}
end = getTickCount();
runningTime = end - start;
writeOutput("Running time: #runningTime#ms to load #arrayLen(files)# objects");
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment