2

how can I display the time of calculation of any software operation? For example:

seq 1 5 | awk '{sum+=$1} END {print sum}'

4 Answers4

3

Do you mean something like this?

$ time seq 1 5 | awk '{sum+=$1} END {print sum}'
15

real    0m0.019s
user    0m0.000s
sys 0m0.000s
Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
1

Just prepend time:

time seq 1 5 | awk '{sum+=$1} END {print sum}'

Output:

15

real    0m0.063s
user    0m0.076s
sys     0m0.030s
choroba
  • 231,213
  • 25
  • 204
  • 289
1

You can use time command:

$ time seq 1 5 | awk '{sum+=$1} END {print sum}'
Michael Kazarian
  • 4,376
  • 1
  • 21
  • 25
1

Time is a complex entity, with many possible answers. Do you want the amount of time the CPU was blocked? The amount of time the process was alive? The amount of time the user had to wait for an answer? Or some other meaning of time altogether.

Usually you can get what you need from the POSIX time utility.

time { seq 1 5 | awk … }

real    0m0.005s
user    0m0.002s
sys 0m0.003s

real is the total time elapsed.

user is the amount of CPU time spent outside the kernel. (User mode CPU time.)

sys is the amount of CPU time spent within the kernel.

There is a more complete explanation at What do 'real', 'user' and 'sys' mean in the output of time(1)?

Community
  • 1
  • 1
kojiro
  • 74,557
  • 19
  • 143
  • 201