Shell Script to Get The Time Difference
I was trying to estimate what is the time spent for a curl command.
So I made a simple shell script for this.
First
create a script name timediff.sh
1
$ vim timediff.sh
Second
Append text as follows:1
2
3
4
5
6
7
8
9
10
11
12
13
14#!/bin/bash
echo "==========START=========="
date
START=$(date +%s%3N) # %3N means in miliseconds
# Start your script work here
echo "processing..."
sleep 2 # sleep for 2 seconds.
# End
END=$(date +%s%3N)
echo
echo "==========END============"
date
DIFF=$(( $END - $START ))
echo "It took $DIFF ms."
Third
Save and execute the following script:1
$ chmod +x timediff.sh
Finally
Execute the script:1
$ ./timediff.sh
Output:1
2
3
4
5
6==========START==========
二 10月 27 09:32:50 UTC 2015
processing...
==========END==========
二 10月 27 09:32:52 UTC 2015
It took 2002 ms.