Linux performance tuning:
https://www.linkedin.com/learning/linux-performance-tuning?trk=eml-email_learning_engagement_single_01-learning_recommendations-4-null&trkEmail=eml-email_learning_engagement_single_01-learning_recommendations-4-null-null-asylfx~jo4nf03y~ja-null-learning~course&lipi=urn%3Ali%3Apage%3Aemail_email_learning_engagement_single_01%3BZvLe9h85RFG5%2FUEcK7sbgw%3D%3D
A Time
1. The time command in shell
/usr/bin/time <command>
Example1
/usr/bin/time sleep 2
Output1:
0.00user 0.00system 0:02.01elapsed 0%CPU (0avgtext+0avgdata 4944maxresident)k
0inputs+0outputs (0major+55minor)pagefaults 0swaps
Example2
#! /bin/bash
###loop.ah####
x=$((x+1))
/bin/pwd > /dev/null
if [ $x -gt 5000 ]
then
exit
fi
done
#########Run "time loop.sh" in bash####
bash-3.2$ time ./loop.sh
Output2:
real 0m8.698s
user 0m2.181s
sys 0m5.474s
2. time command in C
- gettimeof day()
- clock_gettime()
B. Operations per Second
C. The strace command
It can helps out check the time usage detail. (We can find the time of using '/bin/pwd' is much longer than using 'pwd'.
So when the type of command is "a shell builtin", we'd better use the command directly.
strace -c -o <files to save output> <command> ####Example#### strace -c -o /tmp/s.out ./loop.sh
##### check the output ###
head -4 /tmp/s.out
output:
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
31.41 0.093416 4 25007 fcntl
18.96 0.056396 4 15010 rt_sigprocmask
浙公网安备 33010602011771号