how to use GNU Time with pipeline how to use GNU Time with pipeline bash bash

how to use GNU Time with pipeline


Call the shell from time:

/usr/bin/time -f "%es" bash -c "ls | wc"

Of course, this will include the shell start-up time as well; it shouldn't be too much, but if you're on a system that has a lightweight shell like dash (and it's sufficient to do what you need), then you could use that to minimize the start-up time overhead:

/usr/bin/time -f "%es" dash -c "ls | wc"

Another option would be to just time the command you are actually interested in, which is the psql command. time will pass its standard input to the program being executed, so you can run it on just one component of the pipeline:

echo "SELECT * FROM sometable" | /usr/bin/time -f "%es" psql


Create a script that calls your pipeline. Then

/usr/bin/time -f '%es' script.sh