count() является ресурсоёмкой функцией, то есть её выполнение для больших массивов интерпретатору даётся "тяжело":
If you want to run through large arrays don't use count() function in the loops , its a over head in performance, copy the count() value into a variable and use that value in loops for a better performance. (отсюда)