They both use would four times, which is odd, but I see what you're driving at.
Edit: to explain the differences as I see them:
the first way:
Every once in a while I would go to this friend's house and we would get into a discussion.
You begin describing a series of events that all occurred in the past.
By the time I would realize,
but once you've said this, you're describing a future possibility, which disagrees with the tense of your introduction.
For example, I don't live close enough to the office to go home for lunch. By the time I would get to my apartment, I would have to turn around and go back to work.
That said, you can't use realize on its own in this context. You need to use it, which you do:
it would have taken 4 hours.
but it should immediately follow realize.
Bottom line, the first sentence wins. Would have taken is correct, because it keeps you in the past.
However, may I suggest:
Every once in a while I would go this friend's house and we would get into a discussion. Before I knew it, four hours had passed.