Naresh
Naresh

Reputation: 2781

execution time and memory uses by the code

I am a PHP coder. I don't find any way to get how many time is taken during execution of code.means execution time. and How much memory space is used by the code during execution tim

I know the PHP INI setting but doesn't showed my solution.

How could i get that time and memory space unit with coding.

Upvotes: 4

Views: 3982

Answers (3)

Phodard
Phodard

Reputation: 41

I found this one in generator example.

$start_time=microtime(true);

//do something what you want to measure

$end_time=microtime(true);
echo "time: ", bcsub($end_time, $start_time, 4), "\n";
echo "memory (byte): ", memory_get_peak_usage(true), "\n";

http://php.net/manual/en/language.generators.overview.php#114136

Upvotes: 4

Borniet
Borniet

Reputation: 3546

I always use

microtime()

for timing, and

memory_get_usage()

for memory usage, together with my IDE (PHPStorm) and XDEBUG this gives quite some useful info.

http://www.php.net/manual/en/function.microtime.php and http://php.net/manual/en/function.memory-get-usage.php

Upvotes: 2

MatRt
MatRt

Reputation: 3534

You can use

microtime()

at the begin of your script, and at the end. The difference will be the execution time. microtime return the timestamp with micro second wich is enough for your needs.

http://www.php.net/manual/en/function.microtime.php

Upvotes: 1

Related Questions