Added duration logging to the generate function