Timer: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
|||
| Line 16: | Line 16: | ||
{{Linux}} console, {{Mac}} Terminal or Cygwin commands on {{Win}}<ref>[http://stackoverflow.com/questions/385408/get-program-execution-time-in-the-shell linux - Get program execution time in the shell - Stack Overflow]</ref><ref>[http://stackoverflow.com/questions/12199631/convert-seconds-to-hours-minutes-seconds bash - Convert seconds to hours, minutes, seconds - Stack Overflow]</ref> | {{Linux}} console, {{Mac}} Terminal or Cygwin commands on {{Win}}<ref>[http://stackoverflow.com/questions/385408/get-program-execution-time-in-the-shell linux - Get program execution time in the shell - Stack Overflow]</ref><ref>[http://stackoverflow.com/questions/12199631/convert-seconds-to-hours-minutes-seconds bash - Convert seconds to hours, minutes, seconds - Stack Overflow]</ref> | ||
<pre> | <pre> | ||
# start the timer | |||
START=$(date +%s) | START=$(date +%s) | ||
| Line 21: | Line 22: | ||
sleep 2s | sleep 2s | ||
# stop the timer | |||
END=$(date +%s) | END=$(date +%s) | ||
DIFF=$(( $END - $START )) | DIFF=$(( $END - $START )) | ||
Revision as of 14:10, 2 February 2017
Get the execution time of the script or sql query.
PHP
Start and stop a timer PHP - Stack Overflow
MySQL
Recording the time elapsed after the sql query was executed.
SELECT @timer := CURRENT_TIMESTAMP(); SELECT SLEEP(2); /* sleep 2 seconds for testing purpose */ SELECT 'custom message' AS 'action', CURRENT_TIMESTAMP() AS 'end time', @timer AS 'start time', TIMEDIFF(CURRENT_TIMESTAMP(), @timer) AS 'time elapsed';
Linux command (BASH)
Linux
console, macOS
Terminal or Cygwin commands on Win
[1][2]
# start the timer START=$(date +%s) # sleep 2 seconds for testing purpose sleep 2s # stop the timer END=$(date +%s) DIFF=$(( $END - $START )) printf "Elapsed time %02dh:%02dm:%02ds\n" $(($DIFF/3600)) $(($DIFF%3600/60)) $(($DIFF%60)) # expected result: # Elapsed time 00h:00m:02s
Python
performance - Measure time elapsed in Python? - Stack Overflow
References