There is no universal answer to your question, unfortunately. Nic did a nice job, but to your second comment and why there is no single answer:

"Because speed is based on pressure behind the bullet, and pressure is a function of heat, volume, etc, certainly somewhere someone has come up with a formula using all the various known parameters to calculate that optimum length". There are always variables which make that impossible, without an acceptable tolerance. All powders should be expected to vary by 10% between lots. I've pressure tested less, but pressure tested much larger swings between lots. Likewise case capacity, and primer output will have variances. Increased fouling and barrel dimensions are all variables. Likewise every powder will have it's happy place in terms of operating pressures in any given cartridge. But the newer progressive powders actually change their burning curve, as pressures change. So the amount of effective push being accomplished by the duration of the curve changes as well.

So as Nic said, what is it that your are after? Most Velocity at any cost? Highest velocity per dollar spent?