RE: 22 or 24
Generally, if you take two identical cartridges and fire them out of two different handguns, one with a short barrel, one with a longer barrel, the longer-barreled handgun will fire the bullet faster, farther and with a flatter trajectory.
Longer barrels give powder more time to burn behind the bullet, generating greater muzzle velocity and therefore downrange velocity. Also, being longer gives a barrel more time to impart spin to the bullet, helping ensure its accuracy.