Ok, I investigated a bit, here are my conclusions :
1. The maximum speed when sprinting is 768 (which is 3px/frame)
The maximum when walking is 384 (1.5px/frame)
2. When sprinting, the speed increases by 70/frame
When walking, the speed increases or decreases by 25/frame (it increases when below 384, but we don't care about this)
3. The speed is not capped at 768, instead it just decreases by 70 when it is above. That's why it bounces every frame. Above, below, above, below...
4. 70 and 25 being multiples of 5, the maximum speed we can have is 765/835
The worst sprint is 700/770
5. Its a little more complicated though, the speed goes directly from 0 to 360 if you sprint from first frame (75 if you walk), then only after this it increases by 70/frame (25 if walk)
6. Considering you start with 360, with
https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm I've come to conclusion that you need to drop (release B) at least 9 frames to be able to reach 765
360 + 9*70 -
9*25 = 765
(that's already what we're doing, in the image above or memory's video we have 9 frames without B)
7. When to drop the frames ? In order to lose the least possible time we need to do it at the highest speed. Do not drop frames from beginning ! Only drop them above 768, that way you can manipulate speed while still running fast. Pressing B while above 768 is very bad since you will lose 70 speed instead of only losing 25 if you release the key.
That means a very simple rule :
-> If speed>768 but isn't 835, release B
-> Every other case, press B
This way is better than the previous image.
8. I thought that even after reaching 835, since when you keep pressing B you lose 70, it could have been better to release B, lose 25, lose 25 again etc, so you maintain yourself longer above 800 speed, but it doesn't work.
Luckily, maintaining B and the 765/835 speed is better than repeating the process infinitely, so we won't have to do 50000 frames one by one.
9. Same process applies after a jump or anything that break the 835 speed
Note : it seems better to jump on a 835 frame and drop on the ground at a 765 one than the opposite (most of the time we wont really have the choice though)
10.
I'm still not sure this is the best way to start, this is only if we start at 360 speed (see point 5.), maybe we can drop less frames in total by starting walking for one or two frames.
Edit: I did more testing and math, starting by walking before running is useless. The image above is good.
11. Numbers must be different on SNES, but the idea should be the same.