Black lives matter
Portrait Dr. Axel Rauschmayer
Dr. Axel Rauschmayer
Homepage | Twitter
Cover of book “JavaScript for impatient programmers”
Book, exercises, quizzes
(free to read online)
Cover of book “Deep JavaScript”
Book (50% free online)
Cover of book “Tackling TypeScript”
Book (first part free online)
Logo of newsletter “ES.next news”
Newsletter (free)

Use Bash as a stop watch

[2010-10-27] dev, hack, shell
(Ad, please don’t block)

If you need to time something and don’t want to use any fancy GUI apps, you can use the following command in the Bash shell (Mac OS X or Linux terminal):

date ; read -n 1 -s ; date
Explanation: Print out time and date, wait for a single key to be pressed (-s prevents that key from being shown), and print out time and date again.

Update 2010-12-12: Great suggestion from the comments. The following is an even simpler solution (hit return at the end of the line to start the stop watch, hit return again to stop it).
time read