|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-08-02 14:55 UTC] petr dot hrabal at gmail dot com
Description: ------------ I have large MySQL query (1.8M rows, 25 columns - all string between 20 and 256 chars) and I need to make 2 dimensional array from it (memory table based on primary key). Code works as expected, but $table creation takes a long time in PHP7.0.9 or 7.1.0-dev same proble apears when PDO is used more extensive info/diagnostics at http://stackoverflow.com/questions/38614982/mysqli-fetch-assoc-performance-php5-4-vs-php7-0 with tested dataset PHP5.x performs 10 times faster Test script: --------------- $vysledek = mysqli_query ( $conn,"SELECT * FROM `table` WHERE 1"); while($zaznam = mysqli_fetch_assoc ( $vysledek )){ $table[$zaznam['prikey']] = $zaznam; } Patchesmm-01.diff (last revision 2016-10-24 08:53 UTC by dmitry@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 08:00:02 2025 UTC |
It's not really necessary to bring mysql into this. Just allocating a bunch of strings without deallocating them in between is enough: <?php $n = 50000000; $s = "aaaaaaaaaaaaaaaaaaaaa"; $a = []; $t = microtime(true); for ($i = 0; $i < $n; $i++) { $s++; $a[] = $s; } var_dump(microtime(true) - $t); This gives me the following results with and without ZMM: nikic@saturn:~/php-src-fast$ sapi/cli/php -d memory_limit=-1 t043.php float(30.064018011093) nikic@saturn:~/php-src-fast$ USE_ZEND_ALLOC=0 sapi/cli/php -d memory_limit=-1 t043.php float(3.7853488922119) Generally the ZMM is somewhat faster than the system allocator, not 20x slower. Assigning to dmitry...