Created
May 20, 2020 07:10
-
-
Save trycf/c3e97f8c79c4ede209582cb00b354860 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> | |
function testNS(susi) { | |
local.whatever=1; // added to give testLS the same starting pos | |
if(susi==1) susi=2; | |
} | |
function testLS() { | |
local.susi=1; | |
if(susi==1) susi=2; | |
} | |
function testWS(susi) { | |
local.whatever=1; // added to give testLS the same starting pos | |
if(arguments.susi==1) arguments.susi=2; | |
} | |
iterations=100000; | |
loop times=20 { | |
// WITH SCOPE | |
var start=getTickCount(); | |
loop from=1 to=iterations item="local.i" { | |
testWS(1); | |
} | |
var res=getTickCount()-start | |
if(isNull(fastest.withArg) || fastest.withArg>res ) fastest.withArg=res; | |
// WITHOUT SCOPE | |
var start=getTickCount(); | |
loop from=1 to=iterations item="local.i" { | |
testNS(1); | |
} | |
var res=getTickCount()-start | |
if(isNull(fastest.withoutArg) || fastest.withoutArg>res ) fastest.withoutArg=res; | |
// WITH Local SCOPE | |
var start=getTickCount(); | |
loop from=1 to=iterations item="local.i" { | |
testLS(1); | |
} | |
var res=getTickCount()-start | |
if(isNull(fastest.withLocal) || fastest.withLocal>res ) fastest.withLocal=res; | |
} | |
dump(fastest); | |
dump(label:"diff between no scope definition and arg def in %",var:int(100-(100/fastest.withoutArg*fastest.withArg))&"%"); | |
dump(label:"diff between arg and local scope in %",var:int(100-(100/fastest.withoutArg*fastest.withLocal))&"%"); | |
dump(label:"diff between no scope definition local access and arg in %",var:int(100-(100/fastest.withLocal*fastest.withArg))&"%"); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment