Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZSH: How to time a block of code?

Tags:

In bash I am able to write a script that contains something like this:

{ time {  #series of commands echo "something" echo "another command" echo "blah blah blah"  } } 2> $LOGFILE 

In ZSH the equivalent code does not work and I can not figure out how to make it work for me. This code works but I don't exactly know how to get it to wrap multiple commands.

{ time echo "something" } 2>&1 

I know I can create a new script and put the commands in there then time the execution properly, but is there a way to do it either using functions or a similar method to the bash above?

like image 399
cldfzn Avatar asked Jul 14 '11 12:07

cldfzn


1 Answers

Try the following instead:

{ time ( echo hello ; sleep 10s;  echo hola ; ) } 2>&1  
like image 63
Zsolt Botykai Avatar answered Nov 16 '22 11:11

Zsolt Botykai