First, the native environment
CPU Information Intel (R) Core (TM) i3 CPU - 2 . 27GHz
Intel (R) Core (TM) i3 CPU M @ 2.27GHz
Intel (R) Core (TM) i3 CPU M @ 2. 27GHz
Intel (R) Core (TM) i3 CPU M @ 2. 27GHz
Memory information
1990228 KB
Second, build the test code
1. Test code
#include <iostream>#include<unistd.h>using namespacestd;#defineElapsedTime 1intMain (void) {cout<<"Current pid:"<< getpid () <<Endl;
while(1) { //Usleep (elapsedtime); } return 0;}
2. Compiling
# g++-O test_usleep.o test_usleep.cpp
3. Running
#./TEST_USLEEP.O
Third, CPU occupancy rate
Note: When testing TEST_USLEEP.O, do not run other programs.
1. No "usleep (elapsedtime);" This line of code
CPU usage:99.9%%cpu%MEM time+954003368893 76099.90.00:07.52
2. #define ELAPSEDTIME 1//1 μs
CPU usage:99.9%%cpu%MEM time+955603368872 76099.90.00:05.10
3. #define ELAPSEDTIME 10//10 μs
CPU usage:14.0%%cpu%MEM time+959603368868 76014.00.00:09.99 TEST_USLEEP.O
4. #define ELAPSEDTIME 100//100 μs
CPU usage:11.7%%cpu%MEM time+961003368868 76011.70.00:05.16
5. #define ELAPSEDTIME 1000//1000 μs =1 ms
CPU usage:1.7%%cpu%MEM time+962403368868 760 1.7 0.0 0:00.79 TEST_USLEEP.O
6. #define ELAPSEDTIME 10000//10000 μs =10 ms
CPU usage:0.3%%cpu%MEM time+963403368868 760 0.3 0.0 0:00.04
7. #define ELAPSEDTIME 100000//100000 μs =100 ms
CPU usage:0.0%%cpu%MEM time+964403368872 760 0.0 0.0 0:00.00 TEST_USLEEP.O
Iv. Reference Information
1.linux, get CPU information
Cat/proc/cpuinfo
2.linux, get memory information
Cat/proc/meminfo
3.linux, use top to view status information for a single process
Top-p PID
V. Web site
Http://www.cnblogs.com/tom-and-jerry/p/3978797.html
End
[Rk_2014_0918]linux, test the effect of usleep function on CPU utilization