Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Created December 31, 2012 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcameron/4420961 to your computer and use it in GitHub Desktop.
Save adamcameron/4420961 to your computer and use it in GitHub Desktop.
Sample code for blofg article: creating a large string, and recording some performance metrics
<cfscript>
param name="URL.magnitude" default=0;
param name="URL.method" default="string";
param name="URL.reset" type="boolean" default=false;
</cfscript>
<cfapplication name="createString_#URL.method#_#URL.magnitude#" sessionmanagement="true">
<cfscript>
param name="session.cumulative" default={count=0, total=0, mean=0};
if (URL.reset){
session.cumulative = {count=0, total=0, mean=0};
}
stringLength = 10^URL.magnitude;
switch (URL.method){
case "string": {
include "string.cfm";
break;
}
case "stringBuffer": {
include "stringBuffer.cfm";
break;
}
case "cfsavecontent": {
include "cfsavecontent.cfm";
break;
}
default: {
throw(
"Invalid METHOD",
"InvalidMethodException",
"A method parameter must be passed on the URL, and be one of STRING, STRINGBUFFER, CFSAVECONTENT"
);
}
}
executionTime = endTime-startTime;
session.cumulative.count++;
session.cumulative.total += executionTime;
session.cumulative.mean = session.cumulative.total \ session.cumulative.count;
writeDump({
expectedSize = stringLength,
actualSize = len(s),
firstHundred = left(s, 100),
last = right(s, 1),
executionTime = executionTime,
urlParams = URL,
cumulative = session.cumulative
});
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment