
11.12.2009, 20:11
|
|
Регистрация: Dec 2009
Сообщений: 2
|
The post is not about if its faster to preallocate array or not.
It should be faster to preallocate but it's a VERY small difference.
The real difference is when you have an array starting at zero and all values are filled.
parsing an array of 10000 elements (with nothing at index 0) is a LOT slower
than parsing the same array with something at index 0.
Test 1:
i = 1;
while ( i < loopCount ) { arr [ i ] = 1 ; i++; } //Trace the speed here
Test 2:
i = 0;
while ( i < loopCount ) { arr [ i ] = 1 ; i++; } //Trace the speed here
Then do the same thing with read.
|