Windows下用來測試cpu性能的super pi大家一定很熟悉吧,下面介紹一個與super pi 類似的Linux命令。
說明:藍色=命令名稱
淺綠=命令參數
淺藍=選項
紫色=目錄
系統環境:CentOS 6.2 i686
命令:time echo "scale=500;4*a(1)"|bc -l -q(紅色部分為小數點後的位數,bc詳解見補充內容)
650) this.width=650;" border=0>
簡單腳本:
- #!/usr/bin/env python
- echo "Please input the number:"
- read a
- echo "Please wait amount for the result......."
- time echo "scale=$a;4*a(1)"|bc -l
- exit
補充:
bc是An arbitrary precision calculator language,即一個任意精度的計算語言,注意是一種語言,它提供了一些語法結構,比如條件判斷、循環等,可以說是很強大的,但是我在實際中還沒有找到需要這個用途的場合 。另外一個用途就是用來進行進制轉換。
常用參數:
-q 不輸出提示
-l 調入數學庫
實例:
a)命令行方式(類似python的解釋器):
650) this.width=650;" border=0>
b)echo 管道方式:
1、計算2的10次方:echo "2^10"|bc
650) this.width=650;" border=0>
2、計算1除以27,並保留10位小數:echo "scale=10;1/27" | bc
650) this.width=650;" border=0>
c)進制轉換
1)二進制10011011轉成十進制:echo "ibase=2;10011011"|bc
650) this.width=650;" border=0>
2)輸入十進制10000轉成八進制:echo "obase=8;10000"|bc
650) this.width=650;" border=0>
bc還有很多妙用大家在應用中慢慢發覺吧。