Created
September 22, 2018 21:43
-
-
Save trycf/3f159cd4aa68e5a0dec52a4a6db267a3 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> | |
writeOutput("<h1>Performance test for structParamExists()</h1>"); | |
num_iterations = 1*1000*1000; | |
setLocale("Italian (Standard)"); | |
writeOutput("<br>Num. iterations: #LSNumberFormat(num_iterations, '_,___')#<br>"); | |
attr = { | |
key1 = "key1" | |
}; | |
native_start_time = getTickCount(); | |
for(i=1; i<=num_iterations; i++) { | |
if (structKeyExists(attr, "key1") and len(trim(attr.key1)) gt 0) { | |
//do stuff here | |
} | |
} | |
native_end_time = getTickCount(); | |
native_tot_time = native_end_time - native_start_time; | |
writeOutput("<br><b>Native</b> functions in #native_tot_time#ms<br>"); | |
/********************************************************/ | |
custom_start_time = getTickCount(); | |
for(i=1; i<=num_iterations; i++) { | |
if (structParamExists(attr, "key1")) { | |
//do stuff here | |
} | |
} | |
custom_end_time = getTickCount(); | |
custom_tot_time = custom_end_time - custom_start_time; | |
writeOutput("<br><b>Custom</b> function in #custom_tot_time#ms<br>"); | |
increment = custom_tot_time / native_tot_time * 100; | |
writeOutput("<br>Increment #int(increment)#%<br>"); | |
</cfscript> | |
<cffunction name="structParamExists" returntype="boolean" output="false"> | |
<cfargument name="args" type="struct" required="true"> | |
<cfargument name="key" type="string" required="true"> | |
<cfscript> | |
if(structKeyExists(arguments.args, arguments.key) and len(trim(arguments.args["#arguments.key#"])) gt 0){ | |
return true; | |
}else{ | |
return false; | |
} | |
</cfscript> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment