Based on the other answers, there are two plausible approaches:
Approach 1. Check whether $n$ is prime or not. If it is not, factor it, then use the factorization of $n$ to compute the number of divisors of $n$. (As suggested by Yuval Filmus and Ricky Demer.)
Approach 2. Check whether $n$ is prime or not. If it is not, find all prime factors that are at most $n^{1/3}$, and write $n=rs$ where all prime divisors of $r$ are at most $n^{1/3}$ and all prime factors of $s$ are larger than $n^{1/3}$. Check whether $s$ is prime or not. Use the known factorization of $r$ and the primality status of $s$ to compute the number of divisors of $n$. (As suggested by gnasher729.)
Approach 1 is asymptotically faster, as I will show below.
In particular, Approach 1 requires factoring arbitrary large numbers. According to current knowledge, the asymptotically fastest algorithm for this is the general number field sieve (GNFS). Its worst-case running time is
$$L_n[1/3, \sqrt[3]{64/9}] = \exp((\sqrt[3]{64/9} + o(1)) (\ln n)^{1/3} (\ln \ln n)^{2/3}).$$
(You can check whether a number is prime or not in polynomial time, and very efficiently in practice, so the time to do that will be far smaller than the time to do everything else.)
Approach 2 requires finding all prime factors of $n$ that are at most $n^{1/3}$. This doesn't necessarily require fully factoring $n$. However, no faster algorithm is known for doing this than to fully factor $n$. According to current knowledge, the asymptotically fastest algorithm for doing this (without trying to fully factor $n$) is the elliptic curve factorization algorithm (ECM). Its worst-case running time is
$$\begin{align*}
L_{n^{1/3}}[1/2, \sqrt{2}] &= \exp((\sqrt{2} + o(1)) (\ln n^{1/3})^{1/2} (\ln \ln n^{1/3})^{1/2})\\
&= \exp((\sqrt{2/3} + o(1)) (\ln n)^{1/2} (\ln \ln n)^{1/2}).
\end{align*}$$
If you compare the two expressions, you will discover that the former is asymptotically faster.
Moreover, I expect that in practice the crossover point will be at a point where $n$ is small enough that you can fully factor $n$ without too much difficulty, so in practice I expect Approach 1 is reasonable for all ranges of $n$. Therefore, I recommend Approach 1: fully factor $n$, using the best available algorithm for that, and then use its factorization to derive how many divisors it has.