We came into NY from the Carib and on St Thomas (US territory) customs came aboard to do the immigration on the penultimate day. It was efficient and fast. Sections of the ship were told to report to immigration at certain times so no long queues. In NY you disembark and hand in your key card, collect your luggage and go to your transport.
I don't know if they still do it but we have sailed many times on QE2 to New York (last time in 2000 )and US customs used to travel with us trans-atlantic so by the time we arrived all checks/visa's etc had been done and on arrival we simply dis-embarked.
Last year with P&O our 1st US port (philadelphia) customs came on board on arrival and the whole process took a couple of hours which considering there were 2000 passengers I think was pretty good. Hope this helps.