How to get the time of several commands with a loop
With zsh:
time (repeat 10 {cmd1; cmd2})
zsh
's repeat
is inherited from csh
.
With tcsh
:
time repeat 10 eval 'cmd1; cmd2'
Would give you the time for each iteration and the overall time at the end.
You can write a simple for
-loop
time -p bash -c "for (( i=0; i<10; i++ )); do command1; command2; done;"
Note that I used bash
instead of sh
for the loop.
For simple for loops you can time the for loop directly:
time for i in {1..10}; do echo $i; sleep 1; done