計算shell指令碼的執行時間

2021-08-04 05:17:27 字數 688 閱讀 4588

有時候可能需要計算 shell 指令碼 執行了多久, 怎麼統計這個指令碼 執行多長時間呢?

直接看 **:

#!/bin/bash

start_time=`date --date='0 days ago' "+%y-%m-%d %h:%m:%s"`

#this is your shell script

sleep 18

##############

finish_time=`date --date='0 days ago' "+%y-%m-%d %h:%m:%s"`

duration=$(($(($(date +%s -d "$finish_time")-$(date +%s -d "$start_time")))))

echo "this shell script execution duration: $duration"

其中date  +%s        自utc 時間 1970-01-01 00:00:00 以來所經過的秒數

date  -d       -d,--date=字串       顯示指定字串所描述的時間,而非當前時間

這裡把 指定的時間 ,轉化為以s 單位.

date +%s -d "$start_time"

計算執行時間

使用方法 double t double gettickcount do something t double gettickcount t gettickfrequency 所用函式為gettickcount 和gettickfrequency gettickcount 返回cpu自某個時間 如啟...

計算執行時間

import datetime starttime datetime.datetime.now long running endtime datetime.datetime.now print endtime starttime seconds 上例演示了計算執行時間的例子,以秒進行顯示。d1 da...

計算python指令碼執行時間的坑

程式執行時間 cpu時間 io時間 休眠或者等待時間 python程式執行時間大於python程式cpu時間 time.clock import datetime import time starttime time.clock time.sleep 3 endtime time.clock pri...