How to monitor for how much time each line of stdout was the last output line in Bash for benchmarking?

前端 未结 2 1986
谎友^
谎友^ 2021-01-15 08:17

For example, suppose I have the script:

(echo a; sleep 1; echo b; sleep 3; echo c; sleep 2)

which outputs:

a
b
c

2条回答
  •  盖世英雄少女心
    2021-01-15 08:48

    If you're happy with a resolution of seconds, you can use this one-liner:

    t=$SECONDS; (echo a; sleep 1; echo b; sleep 3; echo c; sleep 2) | while read line; do echo $((SECONDS - t)) $line; t=$SECONDS; done
    

    If you are OK with installing node.js, this is exactly what gnomon does:

提交回复
热议问题