Skip to content

Instantly share code, notes, and snippets.

@cybersonic
Created August 18, 2016 09:48
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 cybersonic/946227ea9ddebc7218c2e8f5e7b68961 to your computer and use it in GitHub Desktop.
Save cybersonic/946227ea9ddebc7218c2e8f5e7b68961 to your computer and use it in GitHub Desktop.
<cfscript>
mystruct = {};
timer type="inline" label="population"{
loop from="1" to="20000" index="x"{
mystruct[x] = CreateUUID();
}
}
echo("<br>");
//Create an array with random items to obtain, including misses
keys = [];
timer type="inline" label="index"{
loop from="1" to="30000" index="x"{
keys.append(RandRange(1, 30000 ));
}
}
echo("<br>");
//Go get the items.
timer type="inline" label="getWithStructFind"{
loop array="#keys#" item="i"{
item = getWithStructFind(i);
}
}
echo("<br>");
timer type="inline" label="getWithElvis"{
loop array="#keys#" item="i"{
item = getWithStructFind(i);
}
}
echo("<br>");
timer type="inline" label="getWithStructKeyExists"{
loop array="#keys#" item="i"{
item = getWithStructKeyExists(i);
}
}
echo("<br>");
timer type="inline" label="getWithTryCatch"{
loop array="#keys#" item="i"{
item = getWithTryCatch(i);
}
}
echo("<br>");
function getWithStructFind(key){
return StructFind(mystruct, key, 0);
}
function getWithElvis(key){
return mystruct[key] ?: 0;
}
function getWithStructKeyExists(key){
return mystruct.keyExists(key) ? mystruct[key] : 0;
}
function getWithTryCatch(key){
try{
return variables.mystruct[key];
}
catch(Any e){
return 0;
}
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment