How to Measure Script Execution Time in PHP? Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Measuring the script execution time in PHP is the time required to execute the PHP script. To calculate script execution time use clock time rather than the CPU execution time. Measuring script execution time is useful to check and improve the execution time for better application performance.Measuring Script Execution using microtime() FunctionThe most commonly used method to measure script execution time in PHP is the microtime() function. This function returns the current Unix timestamp in microseconds, which allows for precise timing of code execution.Example: Measuring script execution timeSample PHP Script php <?php for($i = 1; $i <= 1000; $i++) { echo "Hello Geeks!"; } ?> First use the microtime() function before starts the script and at the end of the script. Then using formula (End_time - Start_time). The microtime() function returns time in seconds. Execution time is not fixed, it depends upon the processor. php <?php // Starting Clock Time in Seconds $start_time = microtime(true); $a = 1; // Start Loop for($i = 1; $i <= 1000; $i++) { $a++; } // End Clock Time in Seconds $end_time = microtime(true); // Calculate the Script Execution Time $execution_time = ($end_time - $start_time); echo "Script Execution Time = " . $execution_time . " sec"; ?> OutputScript Execution Time = 2.1934509277344E-5 secMeasuring Script Execution using hrtime() Function (High-Resolution Timer)PHP 7.3 introduced the hrtime() function, which provides nanosecond-level precision for measuring execution time. This method is ideal for situations where microsecond precision isn't enough, and you need even more detailed performance data.Example: Measuring script execution time with hrtime() function. PHP <?php // Start Measuring Time $start_time = hrtime(true); // Example Script for ($i = 0; $i < 1000000; $i++) { $x = sqrt($i); } // End Measuring Time $end_time = hrtime(true); // Calculate Execution time (in Nanoseconds) $execution_time = $end_time - $start_time; // Convert to Seconds (1 second = 1 billion nanoseconds) $execution_time_in_seconds = $execution_time / 1e9; echo "Execution time: " . $execution_time_in_seconds . " seconds"; ?> OutputExecution time: 0.020944947 seconds Comment More infoAdvertise with us Next Article How to terminate execution of a script in PHP ? K Komal Agarwal11 Follow Improve Article Tags : Technical Scripter Web Technologies PHP Similar Reads How to increase execution time of a PHP script ? Increasing the execution time of a PHP script means extending the maximum time a script is allowed to run before the server terminates it. This is often necessary for resource-intensive tasks, like data processing or large file uploads, to prevent timeouts.Here we have some common approaches to incr 2 min read How to terminate execution of a script in PHP ? In this article, we are going to discuss how to terminate the execution of a PHP script. In PHP, a coder can terminate the execution of a script by specifying a method/function called the exit() method in a script. Even if the exit() function is called, the shutdown functions and object destructors 2 min read How to Measure Execution Time of Function in R ? In this article, we will learn how to measure the execution or running time of a function in the R programming language. Method 1: Using Sys.time For this first create a sample function that runs for a specific duration. For doing so pass the duration to Sys.sleep() function. Syntax:   startTime 4 min read How to Measure Elapsed Time in Python In Python, we can measure the elapsed time (time taken for a specific task to complete) on executing a code segment or a Python script. It's useful when we are benchmarking the code, debugging or optimizing performance. Python provides several built-in modules to measure the execution time of code b 4 min read How to check the Execution Time of Python script ? Checking the execution time of a python script helps you measure how long a piece of code takes to run. This is useful for analyzing performance, especially when working with large data or complex algorithms.Let's explore different ways to check execution time of python.Using timeit moduletimeit mod 3 min read How is it possible to set an infinite execution time for PHP script ? Yes, it is possible to set an infinite execution time for the PHP Script. We can do it by adding the set_time_limit() function at the beginning of the PHP script. The set_time_limit() function takes only one parameter that is int value which is in seconds and it returns a boolean value. If the scrip 2 min read Like