A good rule of thumb is to stay at least 15-30 minutes, long enough to pay your respects, offer condolences, and maybe even share a story or two. But, if you're close to the family, you may want to stick around longer, to offer more support and be a part of the healing process. Just remember, it's not about the amount of time you stay, but the quality of time you spend with the family and friends.
Now, you might be thinking, what if I didn't know the person that well? Well, in that case, a briefer visit might be more suitable, maybe just long enough to sign the guestbook and offer a quick condolence. But, even in this case, you can still make a positive impact by being there, and showing you care.