Variables scope slower than no scope??


Variables scope slower than no scope??

Posted by Luis Majano
Jul 27, 2007 00:00:00 UTC
I have been twiddling with some performance geekness and created a small test to see if direct scoping the variables scope was faster than not scoping it, and I found some very interesting results. Scoping the variables scope was much slower than not doing it. It is shocking but true. Or maybe my test is foolish, judge for yourself and let me know.

Test Results 1:

Iterations: 30

Loops per Iteration: 5000

Avg No variables scope: 20.8333333333 ms

Avg. using variables scope: 43.7333333333 ms

Setup: Windows XP/IIS/CFMX 7.0.2



Test Results 2:

Iterations: 30

Loops per Iteration: 5000

Avg No variables scope: 4.7 ms

Avg. using variables scope: 11.9666666667 ms

Setup: Windows XP/IIS/CFMX 8 GMC

UPDATES:

Test Results 3:

Iterations: 30

Loops per Iteration: 5000

Avg No variables scope: 8.23333333333 ms

Avg. using variables scope: 17.1333333333 ms

Setup: Mac Intel/Apache/CFMX 7.02

Avg No variables scope: #arraySum(records)/iterations# ms

Avg. using variables scope: #arraySum(records2)/iterations# ms


 


Doug Laakso

What version of ColdFusion are you running?

Luis Majano

Windows XP/IIS/CFMX 7.0.2

Sean Corfield

I was very surprised by this but went ahead and tried it on CF8 Public Beta and the differential was even greater - about a factor of 3-4 in favor of not using VARIABLES scope.

Sean Corfield

Oh, now I'll actually read your blog entry properly... You have the CF8 results too and they match mine pretty well. The no variables case was below 4 seconds on my Mac Intel and the variables case was 12 or above on most runs.

Luis Majano

This is shocking indeed Sean. I will try in a bit on the Intel Mac too and post the results. This should be a great enhancement for framework code.

Mark Mandel

Luis,

This corroborates what I found when I was doing some performance tweaks to Transfer.

I found exactly the same thing that you did: calling via the variables scope is actually slower.

Terry Schmitt

Since I've been testing Railo lately, I figured I'd run this through Railo.

Setup: WinXP host with Win2000serv vmware / RailoRC3 Railix

I also took the average of 10 executions of the code block. The results without scoping varied from 5-9 seconds, but the scoped test was very sold at 3 seconds.

Avg No variables scope: 7.083333333ms Avg. using variables scope: 3.233333333ms

This shows more consistent behavior with what is expected.

Your results were definitely surprising though... In theory a scoped variable should have less overhead... Go figure.

Peter Bell

Wow - that is EXTREMELY surprising. Will be interesting to head something from the CF team when they've wrapped up 8 about what underlies this!

Mark Mandel

Oh, I didn't say, my setup is a Ubuntu, w/ CF8 on Ubuntu 7 vmware vm

zac spitzer

just tried out a test using the arguments scope inside a function, adding the arguments scope is also slower than the un-scoped case..

Avg without arguments scope: 5.2333ms Avg. using arguments scope: 7.26666 ms

Gert Franz

Hi Luis,

it is funny that at last someone did exactly the tests I allways propagated. I guess we spoke about exact the same promlem on the IE Meeting last month. Nice that you tested it. I must say that within components when using the variables scope in MX it makes no difference to not using it. In Railo there should not be such a great difference, allthouigh I expect that using the scope should be slightly faster.

Greetings from Switzerland Gert Franz Customer Care Railo Technologies GmbH [email protected] www.railo.ch

Join our Mailing List http://groups.yahoo.com/group/railo_talk/

Avery

Thank you very much for this article.

Site Updates

Entry Comments

Archives

Entries Search