Tools
- Sandbox
- Paste Code
- Snippets
- Generators
- Checks
- Convertors
How to calculate execution time in PHP
Snippet
Share
Do you find this snippet useful? Then share it with your friends or colleagues. This will help us to make our free web tools better.
To check the execution time of a piece of code you need to use the microtime() function, example:
<?php
//place this before any script you want to calculate time
$time_start = microtime(true);
//do something
$time_end = microtime(true);
// calculate execution time
$execution_time = ($time_end - $time_start);
//execution time of the script
echo 'Total Execution Time: '.number_format((float) $execution_time, 10) .' seconds';