Arithmomania is the compulsive urge to count things, whether you want to or not.
For many people, including myself, this tends to most often take the form of counting things like letters or syllables whenever you hear, say, read, write, or think anything, and then grouping, counting, or otherwise performing elaborate arithmetic on them. It can be pretty exhausting, not to mention distracting.
While arithmomania's usually associated with obsessive-compulsive disorder, for me at least, it seems far more likely a form of stimming.
Autism and allism: Arithmomania