6

when timing a command execution time with sudo, time should be before sudo or after sudo?

time sudo command

or

sudo time command

which one is correct?

the output seems very different to me

    [esolve@xxt ~]$ sudo time ls
    193.144.21.131_udp.folder  lockfile         run_udp.sh    udp_folder
    50IP.txt                   my_ip_host_site  send_udp_log  udp_receiver
    ip_each_site               raw_udp_client   ssh.log
    0.00user 0.00system 0:00.00elapsed ?%CPU (0avgtext+0avgdata 3088maxresident)k
    0inputs+0outputs (0major+236minor)pagefaults 0swaps


    [esolve@xxt ~]$ time sudo ls        
    193.144.21.131_udp.folder  lockfile         run_udp.sh    udp_folder
    50IP.txt                   my_ip_host_site  send_udp_log  udp_receiver
    ip_each_site               raw_udp_client   ssh.log

    real    0m0.004s
    user    0m0.003s
    sys     0m0.002s
    [esolve@xxt ~]$

why they are like this?

13

time sudo command executes your shell's time builtin if it has one, whereas sudo time command always executes the time executable in the program search path ($PATH).

time sudo command includes the time taken by the sudo command, whereas sudo time command doesn't.

You should use sudo time command, because sudo's processing time is small but not always negligible, and its wall clock time may be a lot larger if the user needs to enter a password.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.