Показать сообщение отдельно
Старый 11.12.2009, 20:11
jpauclair вне форума Посмотреть профиль Отправить личное сообщение для jpauclair Найти все сообщения от jpauclair
  № 1  
Ответить с цитированием
jpauclair

Регистрация: 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.