-2

I want to performance test a couple of php functions. What is the easiest approach to repeat code 1000 times and return how long it took all together via microtime()?

Maybe a repeated loop? I came across a very simple code here on SO recently but forgot to favorite it.

Henrik Petterson
  • 6,776
  • 19
  • 65
  • 144
  • i know without looking the manual page for microtome has many examples –  Mar 05 '15 at 01:35
  • "a repeated loop" as opposed to a "non repeated loop" ? –  Mar 05 '15 at 01:36
  • Possible duplicate of [How to benchmark efficiency of PHP script](https://stackoverflow.com/questions/8291366/how-to-benchmark-efficiency-of-php-script) – Jeff Luyet Sep 16 '19 at 13:48

1 Answers1

2

What's so difficult about it? Let's modify this example from PHP Manual

<?php
$time_start = microtime(true);

$times=0;               // This couldn't be tough
while($times<1000)
{
   yourFunction();
   $times++;
}


$time_end = microtime(true);
$time = $time_end - $time_start;

echo "Did yourFunction in $time seconds\n";
?> 
Hanky Panky
  • 45,969
  • 8
  • 69
  • 95