Timer: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
Get the execution time of the script or sql query was executed.
Get the execution time of the script or sql query was executed.


== PHP ==
[http://stackoverflow.com/questions/8310487/start-and-stop-a-timer-php Start and stop a timer PHP - Stack Overflow]


PHP: [http://stackoverflow.com/questions/8310487/start-and-stop-a-timer-php Start and stop a timer PHP - Stack Overflow]


 
== MySQL ==
MySQL: Recording the time elapsed after the sql query was executed.
Recording the time elapsed after the sql query was executed.
<pre>
<pre>
SELECT @timer := CURRENT_TIMESTAMP();
SELECT @timer := CURRENT_TIMESTAMP();
Line 12: Line 13:
</pre>
</pre>


 
== Linux command ==
{{Linux}} 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>
{{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>
<pre>
<pre>
START=$(date +%s)
START=$(date +%s)
# sleep 2 seconds for testing purpose
sleep 2s
sleep 2s
END=$(date +%s)
END=$(date +%s)
DIFF=$(( $END - $START ))
DIFF=$(( $END - $START ))
echo "Elapsed time $DIFF seconds"
echo "Elapsed time $DIFF seconds"
</pre>
</pre>


 
== Python ==
Python: [http://stackoverflow.com/questions/7370801/measure-time-elapsed-in-python performance - Measure time elapsed in Python? - Stack Overflow]
[http://stackoverflow.com/questions/7370801/measure-time-elapsed-in-python performance - Measure time elapsed in Python? - Stack Overflow]





Revision as of 14:28, 8 December 2016

Get the execution time of the script or sql query was executed.

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

Linux Os linux.png console, macOS icon_os_mac.png Terminal or Cygwin commands on Win Os windows.png [1]

START=$(date +%s)

# sleep 2 seconds for testing purpose
sleep 2s

END=$(date +%s)
DIFF=$(( $END - $START ))
echo "Elapsed time $DIFF seconds"

Python

performance - Measure time elapsed in Python? - Stack Overflow


References