This is an interesting question.
The answer depends very much on whether you are circumcised or not. Another factor believe it or not, it what you eat.
Avoid meats and processed foods.
Also the tiniest bit of residue from the last time you ejaculated will cause smegma, or at least an unpleasant odor to form very quickly. Wash your penis everytime you ejaculate. Sometimes just precum can cause the problem, although it seems to take more precum and a longer time for this to happen. Frequently during the week, and randomly, I go to use the bathroom and find my "foreskin area" and head (I am circumcised but with some extra skin) literaly full of precum - and I very rarely can imagine why. If this happens to you, make sure you are checking and washing.