Efficient way of looping through a large amount of users?
You could just setup a criteria model in your “categories” for-loop, prepared to query for the users related to that category. And then use the total() method to get the count.

foreach($category as $interest) {
    $user_criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::User);
    $user_criteria-&gt;relatedTo = $interest-&gt;id;
    $count = $user_criteria-&gt;total();

    $interestArray[$interest-&gt;title] = $count;
}


Using the total() method is a lot faster than find(), the underlaying SQL which is necessary to get the amount of rows performs better and Craft also doesn’t have to populate the Entry models with all the data.

(Not sure why @LukePearce deleted his answer, where he basically suggested to do the same thing.)