How to run "time" on a function in zsh

justingordon

This works:

time ls -l

This does not work

f() { ls -l }
time f

No time output is printed in the second case. Why?

mpy

@John1024 gave you the answer for bash. I try to answer the zsh tag...

You get the timing statistics, if you spawn a subshell for your function:

% zsh
% f() { sleep 1 }
% time f
% time (f)
( f; )  0.00s user 0.05s system 4% cpu 1.061 total
% time sleep 1
sleep 1  0.00s user 0.03s system 2% cpu 1.045 total

This adds a little overhead, but as you can see from this (non-faked ;)) example, it's probably insignificant.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to run a function at specific time & date?

From Dev

How to run a function at a specific time in iOS?

From Dev

How to compile a function at run-time?

From Dev

How to make a function run for a particular time period?

From Dev

how to run a javascript function on the given date time

From Dev

How to put arguments in a function at run time?

From Dev

How to increase a number every time a function is run?

From Dev

How to use watch with a function in zsh?

From Java

How to run a function in Django after a certain time passed by

From Dev

How does function overloading work at run-time, and why overload?

From Dev

How can I make my function run in constant time?

From Dev

In JavaScript, how can I have a function run at a specific time?

From Dev

How to set a time limit to run asynchronous function in node.js?

From Dev

How to run a php function inside a div without refreshing each time

From Dev

How to run a function a certain number of times with a specific time interval

From Dev

How to use xarray to group by time and then run a bin function on the groups?

From Dev

How to run a function when Ember finished loading for the first time

From Dev

How does function overloading work at run-time, and why overload?

From Dev

How can I run function for each element in different time?

From Dev

How to pass run time arguments to a function in c through a shell script

From Dev

How to run a function that sums numbers over time, and logs the sum in a variable?

From Dev

How do I run grep on a zsh variable?

From Dev

How to interactively run all commands in a file in zsh?

From Dev

How to get execution millisecond time of a command in zsh?

From Dev

Run a function for a specific amount of time

From Dev

How to run a function after specific time then switch it off after specific time?

From Dev

Trying to understand this function from Go, why make a function that always run in constant time and how does this work?

From Dev

How would I prevent a random function from choosing the last outcome of that function when run another time?

From Dev

How to add double quotes to zsh function arguments?

Related Related

  1. 1

    How to run a function at specific time & date?

  2. 2

    How to run a function at a specific time in iOS?

  3. 3

    How to compile a function at run-time?

  4. 4

    How to make a function run for a particular time period?

  5. 5

    how to run a javascript function on the given date time

  6. 6

    How to put arguments in a function at run time?

  7. 7

    How to increase a number every time a function is run?

  8. 8

    How to use watch with a function in zsh?

  9. 9

    How to run a function in Django after a certain time passed by

  10. 10

    How does function overloading work at run-time, and why overload?

  11. 11

    How can I make my function run in constant time?

  12. 12

    In JavaScript, how can I have a function run at a specific time?

  13. 13

    How to set a time limit to run asynchronous function in node.js?

  14. 14

    How to run a php function inside a div without refreshing each time

  15. 15

    How to run a function a certain number of times with a specific time interval

  16. 16

    How to use xarray to group by time and then run a bin function on the groups?

  17. 17

    How to run a function when Ember finished loading for the first time

  18. 18

    How does function overloading work at run-time, and why overload?

  19. 19

    How can I run function for each element in different time?

  20. 20

    How to pass run time arguments to a function in c through a shell script

  21. 21

    How to run a function that sums numbers over time, and logs the sum in a variable?

  22. 22

    How do I run grep on a zsh variable?

  23. 23

    How to interactively run all commands in a file in zsh?

  24. 24

    How to get execution millisecond time of a command in zsh?

  25. 25

    Run a function for a specific amount of time

  26. 26

    How to run a function after specific time then switch it off after specific time?

  27. 27

    Trying to understand this function from Go, why make a function that always run in constant time and how does this work?

  28. 28

    How would I prevent a random function from choosing the last outcome of that function when run another time?

  29. 29

    How to add double quotes to zsh function arguments?

HotTag

Archive