LoginSignup
7
7

More than 5 years have passed since last update.

dateコマンドを使ってプログラムの実行時間を計測する

Posted at

unix時間の取得

$ date +%s
1436081057

プログラムの実行時間を計測する

dateコマンドを使うことで、プログラムの実行時間を計測することができます。

#!/bin/bash
TIME1=`date +%s`
sleep 3
TIME2=`date +%s`
DURATION=`expr ${TIME2} - ${TIME1}`
echo "It took ${DURATION} sec."

これを実行すると、"It took 3 sec."と出力されます。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7