PHP Calculation Program Execution time

Source: Internet
Author: User
How does PHP calculate program execution time? This paper mainly introduces the method of PHP computational program execution time, taking the MD5 function encryption run time as an example to analyze the PHP calculation function running time skills. We hope to help you.

This example describes how PHP calculates the execution time of a function. Share to everyone for your reference. Specific as follows:

We can record the start and end time respectively before and after the program, the two time difference is the execution of the program.


<?php$long_str = "This was a test to see how much time MD5 function takes to execute over this string";//Start timing F Rom Here$start = Microtime (TRUE);//function to TEST$MD5 = MD5 ($long _str), $elapsed = Microtime (True)-$start; echo "that T Ook $elapsed seconds.\n ";? >


The results of the operation are as follows:

That took 7.1525573730469E-6 seconds.

How PHP calculates function execution time and how to get a subtle approach


Get Subtle method function Getmillisecond () {   list ($s 1, $s 2) = explode (' ', Microtime ());   return (float) sprintf ('%.0f ', (Floatval ($s 1) + floatval ($s 2)) * 1000); }


Principle: Record function start time and end time separately, then time difference is function execution


<?php $start _time = Microtime (True); for ($i =1; $i <=1000; $i + +) {echo $i. ' <br> ';} $end _time = Microtime (true); Echo ' Loop execution time is: '. ($end _time-$start _time). ' S ';? >

Related recommendations:

PHP as an explanatory language, and compiled language java,c++ have a performance gap, how to improve PHP efficiency?

PHP performance Analysis and experimentation: a macro analysis of performance

PHP performance Analysis and experimentation: a microscopic analysis of performance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.