Created
August 18, 2016 09:48
-
-
Save cybersonic/946227ea9ddebc7218c2e8f5e7b68961 to your computer and use it in GitHub Desktop.
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
<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