Matrix distance and time calculations