我想测量在PostgreSQL中一些SQL查询的运行时间。使用BASH内置的time,我可以执行以下操作:
$ time (echo "SELECT * FROM sometable" | psql)
我喜欢GNU Time,它提供了更多的格式选项。但是我不知道如何在管道中使用它。为了简单起见,在下面的示例中,我使用ls | wc
:
$ /usr/bin/time -f "%es" (ls | wc)
-bash: syntax error near unexpected token `('
$ /usr/bin/time -f "%es" "ls | wc"
/usr/bin/time: cannot run ls | wc: No such file or directory
如果我没有以任何方式对管道进行分组,它就不会抱怨:
$ /usr/bin/time -f "%es" ls | wc
0.00s
但显然,这只测量了管道的第一部分,如下例所示。
$ /usr/bin/time -f "%es" ls | sleep 20
0.00s
那么问题是使用管道符正确的GNU时间命令的语法是什么?