DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Calculate Command Running Time on Linux


You can use "time" or "/usr/bin/time -p" to calculate the running timespan of a command:

% time vmstat 2 2 procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 1 0 0 2676404 141160 571960 0 0 5 7 64 270 2 1 97 0 0 0 0 2667964 141168 579900 0 0 0 36 234 626 1 1 98 1 vmstat 2 2 0.00s user 0.00s system 0% cpu 2.003 total

% /usr/bin/time -p vmstat 2 2 procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 1 0 0 2675576 141184 571960 0 0 5 7 64 270 2 1 97 0 0 0 0 2675560 141192 571956 0 0 0 100 248 692 1 1 97 1 real 2.00 user 0.00 sys 0.00

You can see the "total" portion of "time" and "real" portion of "/usr/bin/time" both give correct answer, while the former looks more accurate.



Published

Mar 5, 2014

Last Updated

Mar 5, 2014

Category

Tech

Tags

  • Linux 158
  • time 7
  • timespan 1

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor