Most cruise ships leave port at 4 pm or later. Some leave earlier. Boarding usually ends one hour prior to departure so it is best to arrive at least 2 hours before the scheduled embarkation. Be sure to check your travel documents for your specific embarkation time and arrive requirements. Some cruise lines will actually assign you a boarding time when you complete the on-line check in process.
My own preference is to arrive as early as I can and if required secure the earliest possible boarding time. This not only ensure I will not miss the boat, but it will usually allow me to get on board and enjoy a leisurely lunch before the buffet gets crowded. I then have time to explore the ship while waiting for my room to be ready.