有时候为了项目需求需要对CPU性能做一个压力测试,这里提供一种方法。通过对圆周率位数进行计算进而确定CPU性能,根据定义预计执行时间,具体操作如下:

time echo "scale=1000; 4*a(1)" | bc -l -q

通过该命令运行,如果3、4分钟没有出现结果,基本问题就可以定位在CPU上,这里我通过自己的测试机,得出如下数字:

wKioL1nBx8KjNkOFAAD5NXUFdvQ750.png-wh_50

"scale=1000; 4*a(1)"这个表达式具体什么意思我没看明白,但是大概意思应该是将该表达式的交给计算器bc来处理,然后将处理结果的时间输出到屏幕

[root@node01 ~]# bc -h
usage: bc [options] [file ...]
  -h  --help         print this usage and exit
  -i  --interactive  force interactive mode
  -l  --mathlib      use the predefined math routines
  -q  --quiet        don't print initial banner
  -s  --standard     non-standard bc constructs are errors
  -w  --warn         warn about non-standard bc constructs
  -v  --version      print version information and exit
[root@node01 ~]#