For each vs. Do while QlikView macro

I was working on some macro's, and was completely devasted by how slow they executed. So I took a real good look at my code. I remember from my early days with PHP, that the manual stated that Foreach loops were slow. So I replaced my loops with Do While instead, and WHOHAA the macros were as fast as you expect!

To dig a bit deeper into the matter, I did a speed comparison on using Do while and the slow For each. And the discovery was mindblowing. I start creating to arrays, that i will loop through (who by the did the implementation of array in VbScript? You have to declare the size of them, so oldschool). Both arrays are 10000000 records big. And I use this code to loop them: 

	d1 = timer()	
 	c=10000000'arrArrDo.Count
	i=0
	Do While i>c
		arrDo(i)=arrArrDo(i)
		i=i+1
	Loop
	d2 = timer()
	i=0
	For each strFor In arrArrFor 
		arrFor(i)=strFor
		i=i+1
	Next
	d3= timer()

Timer() is how I record the place in time when executed.

The Do While loop took: 0.00312 seconds.
And the Foreach a staggering: 35,85938 second.

What also was eyeballing me, was the huge amount of memory used for this operation. I'm running TinyXP, which used 301 mb ram before the test, and it peaked at over 1.6 gb during the test. Why do you need 1.3 gb for holding 2x10000000 arrays?

I guess the lesson here is don't use arrays in QlikView.

Here's an image og how the Task Manager looked:

Notice th ridiculous peak in memory usage. This happened when I ran the macro. For your info this was version 8.5 SR3.

Hope this is usefull, Regards Seebach