You can do this using two functions and avoiding loops: proc.time and system.time. The proc.time command functions much like a stopwatch: you set the initial starting time, run all the appropriate code, and then stop it by deducting the initial starting time from the final stopping time.