About 30mins-2hrs to lay all the ideas down. I personally don't think of melodies in my head or ahead of time. I just sit down and do one or two thing first randomly (like laying down a chord or drumbeat that sounds good to my likings), then build everything else around it. After that, then yes, some melodies start poppin up in my head for what I should do next,...
I'm not much of a sample using guy, but I think when you use samples, your approach is different. Everything you do then will be built around that sample. For example, you use a drumloop, then that might dictate how your going to go about playing your bassline and vice versa. Have a nice piano sample you want to use as the main melody, then that should dictate what key your going to play the bassline in and everything else.
A beat is really never done though because there's always something you can add or take out, music is pretty much limitless. To "finish up" a beat I really like, it would take longer than 2hrs. I've been up like 4-5hrs str8 till the early morning losing track of time when I really get into a beat.
I can look like a sick insomniac in the morning sometimes. lol Family member getting up to take a piss or something early in the morning and see the back of my head with headphones on bobbin to the beat. haha