Author post count in category

You don’t need to loop through the posts for this.

Instead, just call the method get_posts() which will return an array of posts and then just count the number of posts in that array.

$user_id = get_the_author_meta('ID');

$args = array(
   'author_name'   => $user_id,
   'category_name' => 'categoryname',
);               
$wp_query = new WP_Query($args);

$posts = $wp_query->get_posts();
$my_count = count( $posts );
echo $my_count;

Reference

https://developer.wordpress.org/reference/classes/wp_query/get_posts/