Last active
December 31, 2021 00:07
-
-
Save JamoCA/809c58aaff993cccd979c143f8de7698 to your computer and use it in GitHub Desktop.
Attempt to compare performance of ColdFusion StructKeyExists() versus keyExists() (cfml)
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
<!--- 20211230 https://gist.github.com/JamoCA/809c58aaff993cccd979c143f8de7698 ---> | |
<h2>Attempt to compare performance of StructKeyExists() versus keyExists()</h2> | |
<cfscript> | |
request.nanoTime = createObject("java", "java.lang.System"); | |
numeric function getNano() output=false hint="returns nano time (more accurate)" { | |
return request.nanoTime.nanoTime(); | |
} | |
results = [:]; | |
s = {}; | |
maxLoop = 2000; | |
t = getNano(); | |
for (i=1; i <= maxLoop; i+=1) structKeyExists(s, "a"); | |
results["#numberFormat(maxLoop)# StructKeyExists()"] = val(getNano()-t); | |
t = getNano(); | |
for (i=1; i <= maxLoop; i+=1) s.keyExists("a"); | |
results["#numberFormat(maxLoop)# keyExists()"] = val(getNano()-t); | |
t = getNano(); | |
for (i=1; i <= maxLoop; i+=1) structKeyExists(s, "a"); | |
results["#numberFormat(maxLoop)# StructKeyExists() [2nd]"] = val(getNano()-t); | |
writeOutput("<hr>"); | |
t = getNano(); | |
structKeyExists(s, "a"); | |
results["1 StructKeyExists()"] = val(getNano()-t); | |
t = getNano(); | |
s.keyExists("a"); | |
results["1 keyExists()"] = val(getNano()-t); | |
writeoutput("<div><b>CF Version:</b> #SERVER.ColdFusion.ProductVersion#</div>"); | |
writeDump(var=results, label="StructKeyExists vs keyExists"); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment