Created
June 30, 2018 16:56
-
-
Save trycf/dc7a8a0dcdab11642dfe595f82f5cc5d to your computer and use it in GitHub Desktop.
TryCF Gist
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> | |
dump (server.lucee.version); | |
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