There is a faster way which is this:
Each time an entity is created increment a variable by 1, each time an entity is destroyed decrement a variable by 1. This variable will then always have the number of entities/type instances whatever that are currently in the game.
Each time an entity is created increment a variable by 1, each time an entity is destroyed decrement a variable by 1. This variable will then always have the number of entities/type instances whatever that are currently in the game.