计算sql执行时间(结束时间-开始时间)

#!/bin/bash
function timediff() { # time format:date +"%s.%N", such as 1502758855.907197692 start_time=$1 end_time=$2 start_s=${start_time%.*} start_nanos=${start_time#*.} end_s=${end_time%.*} end_nanos=${end_time#*.} # end_nanos > start_nanos? # Another way, the time part may start with 0, which means # it will be regarded as oct format, use "10#" to ensure # calculateing with decimal if [ "$end_nanos" -lt "$start_nanos" ];then end_s=$(( 10#$end_s - 1 )) end_nanos=$(( 10#$end_nanos + 10**9 )) fi time=$(( 10#$end_s - 10#$start_s )).$(( (10#$end_nanos - 10#$start_nanos)/10**6 )) #return $time echo $time } for i in `seq 1 9` do start=$(date +"%s.%N") psql < ./"10"$i".tpcds.0"$i".sql" end=$(date +"%s.%N") time=`timediff $start $end` echo ""$i"个SQL ""$time" done for i in `seq 110 199` do start=$(date +"%s.%N") after=100 num=$((i-after)) psql < ./$i".tpcds."$num".sql" end=$(date +"%s.%N") time=`timediff $start $end` echo ""$num"个SQL ""$time" done #start=$(date +"%s.%N") # Now exec some command #end=$(date +"%s.%N") # here give the values # start=1502758855.907197692 # end=1502758865.066894173

 

posted @ 2022-10-17 10:17  李小期  阅读(443)  评论(0)    收藏  举报