In working on my editing marks for Who Wants To Be A Hero? I've been reminded that humor has distinct pacing. For me, I'm seeing three separate speeds, dependent on the type of humor ... and of course, timing is everything. A mismatch drains the funny out of even the most clever setup.
1. Quick hit. A snappy remark, terrible pun, etc. Setup for this needs to be subtle; it loses punch if one can see it coming. On the other side, if the characters respond too much or drag out the logical conclusions of the joke, it becomes diluted - unless the follow-up is also comic in nature, of course. This is probably the one I have the most trouble with, and a lot of my editing marks involve paring away the ungainly train behind the joke.
2. Continuous buildup. One quip or moment of humor builds on another, builds on the next, builds on the next ... in this kind of sequence, the length adds to the humor. This kind of back-and-forth can still be ruined by going on too long, and if it's too short, it may never get off the ground. The "level" of the jokes needs to move upwards - save the best for last. I like to do this with pun sequences or a barrage of phrases in the same vein; the first one or two, you may not even notice.
3. Anticipation. This is usually character-based humor, but not always. Here, it's all about the setup and laying out the joke in such a way that the reader knows what is coming and looks forward to it - and their expectations are met perfectly or even exceeded.
I certainly don't claim to be a master humorist, but I enjoy writing humor, and I've published a few stories in a comedic vein. This is actually the second humorous novel I've written: the first, Miss Understanding, involved a group of female adventurers from a fantasy world being dropped into our reality and having to participate in a beauty pageant to win their means home - maybe I'll rewrite it some day. I've learned a lot from Who Wants To Be A Hero? and hopefully, the pay-out of that joke will be publication.