Increasing the number of iterations of a simple loop by 1 significantly increases the execution time.

I need help to figure out the situation with the web server regarding runtime. I noticed a problem when the server returns more characters than ~ 41000 - about 40 KB.

So I made a script:

<?php $php_start_time = MICROTIME(TRUE); echo $_GET['i'].':'; for($i=0;$i<=$_GET['i'];$i++) { echo 'a'; } echo '<br>runtime: '.(MICROTIME(TRUE) - $php_start_time); ?> 

And I try, more than 10 times, several browsers:

when $ _GET ['i'] = 40952 I will bypass 0.013 ... ms

when $ _GET ['i'] = 40953 I will bypass 0.679 ... ms

difference 0.666 for only one char?

I saw that the runtime is very different when trying to get the page results from different places (online proxy).

So, I suppose this is related to distances. I am in the EU, the server is in the USA.

Until I find a way to fix this problem, the script is available at: http://selfreveal.com/speed_test_1.php?i=40953

Also phpinfo (): http://selfreveal.com/phpinfo.php

+4
source share
3 answers

First of all, I assume that you are working with a memory limit and collecting a garbage collector. Try increasing your memory limit:

 ini_set('memory_limit'. '128M'); 
0
source

Timing is not always the same; your computer / server may process another process, which may slow down the other processes that you are currently running.

Try running it 100x or 1000x and then get avarage. You will see that the difference is almost gone.

0
source

You can try adding flush(); right after echo 'a'; and retesting?
you can also try using ob_start() and ob_flush() to make sure that it is not some kind of internal buffer (OS dependent) or something

0
source

Source: https://habr.com/ru/post/1416232/


All Articles