Good day. There is a simple function:

public function exec () { $arr = array(); for($i = 0; $i < 5000000; ++$i) $arr['a' . $i] = $i; return $arr; } 

Do you think the generation and return time is normal for an array network previously processed with json_encode in 1.2 ~ 2 seconds?

PS note the array is associative.

  • do you have about 50mb there, do you know?)) More even) - Sh4dow
  • ok for what? what's the question? - FLK
  • Testing performance. Transfer is carried out by means of sockets .... from localhost by localhost. And memory leaks looked ... whether .. or not. Memory seems to be normal, but I was interested in time .... quickly, slowly ... xs :) PS The processor loads 10% when generating this array and processing json_encode If anyone is interested, I will describe in more detail how and what is done. - Stanislav Komar

2 answers 2

Testing revealed:

  • Classic execution method:

    Creation of the array has ceased critical error already at 601099 position. The generation time is 10.34519290924072

  • "Demonic" multiprocessor method:

    Execution pleased. Only 1.5 ~ 2 seconds for 6.000.000 elements + transmission over the network (instantly)

Regarding memory.

  • The standard method (Apache + Browser) .... !! By the way, I did not output anything to the browser, I just created an array !! brazenly took all my memory from me and ate 80% of the process .... so it also collapsed.

  • "Demonic" - gobbled up less than 15-10% and about 60MB of memory. After that, the memory was instantly cleared.

Total Total. Yesterday there was someone saying that PHP demons are scary? :)) And I think that is very good :)

  • So you add to your demons full support for HTTP (s) / ftp / ssl, output caching and other Apache rolls - and look again. - Sh4dow
  • And the point is to add server-side ctt (c) / ftp / ssl buns? :)) That's what he and server-side :) - Stanislav Komar

Perhaps this is normal, if you need faster, then it is better to generate json yourself.

 $json='{'; foreach ($arr as $k=>$v)){ $json.="'".$k."':'".$v."',"; }; $json.='}'; 
  • PS did not make speed measurements - ReinRaus
  • That's not the point :))) I'm telling you - it was curious about time. I compare the work of PHP as a demon and the classic version. Classic - pedalit :( - Stanislav Komar