I compare two formulas in Matlab, in terms of precision and running time.
Consider the sphere, in Cartesian coordinates:
$x^2 + y^2 + z^2 = \rho^2$
or in spherical coordinates:
$x = \rho \sin(\theta) \cos(\varphi)\\
y = \rho \sin(\theta) \sin(\varphi)\\
z = \rho \cos(\theta)$
Choose a bunch of points on the sphere, for example:
N = 1e6 + 1;
rho_sph = rand;
phi_sph = rand(N, 1) * pi;
theta_sph = rand(N, 1) * pi;
xyz_sph = [rho_sph * sin(theta_sph) .* cos(phi_sph), ...
rho_sph * sin(theta_sph) .* sin(phi_sph), ...
rho_sph * cos(theta_sph)];
Now calculate the distance between each couple of points (1,2), (2,3), ..., (N-1, N).
aa = cross(xyz_sph(1:end-1, :), xyz_sph(2:end, :));
bb = dot(xyz_sph(1:end-1, :)', xyz_sph(2:end, :)');
aa = arrayfun(@(n) norm(aa(n, :)), 1:size(aa, 1));
d1 = rho_sph * atan2(aa, bb)';
% Elapsed time is 12.376257 seconds.
d2 = rho_sph * acos(cos(theta_sph(1:end-1)) .* cos(theta_sph(2:end)) + ...
sin(theta_sph(1:end-1)) .* sin(theta_sph(2:end)) .* ...
cos(phi_sph(1:end-1) - phi_sph(2:end)));
% Elapsed time is 0.264629 seconds.
The first formula is considered more precise, but it's slower; the second is less accurate at the poles, but it's much faster. Otherwise the two solutions are practically equivalent:
plot(d1 - d2, '.')