Speeding up database calls with PDO and iterators

Varianta TL;DR este un pic impresionantă:

Foreach loop

  • Data fetching time for 63992 of 250000 records: 2.14 seconds
  • Data processing time for 63992 of 250000 records: 7.11 seconds
  • Total time for 63992 of 250000 records: 9.25 seconds
  • Memory consumption for 63992 of 250000 records: 217.75MB

Iterator loop

  • Data fetching time for 63992 of 250000 records: 0.92 seconds
  • Data processing time for 63992 of 250000 records: 5.57 seconds
  • Total time for 63992 of 250000 records: 6.49 seconds
  • Memory consumption for 63992 of 250000 records: 0.25MB
3 Likes

Or you could just do while(fetch) {} :smiley: Interesant oricum. Nu am folosit niciodata interatori asa, desi mi-a trecut prin cap de vreo cateva ori, mi s-a parut ca adauga prea multa complexitate.

1 Like

TL;DR

$ composer require doctrine/dbal:2.5.*

PDO on steroids :smile:
Frunzareste pe aici si vezi extra functii
http://www.doctrine-project.org/api/dbal/2.5/namespace-Doctrine.DBAL.html

Eu consider că ar trebui să cunoști chestii mai hardcore - chiar și doar teoretic - înainte de a trece la framework-uri și biblioteci 3rd party :smile:

2 Likes

Nu, stai. SA fiu mai "–verbose"
Doctrine e din 2 bucati DBAL si ORM (impreuna fac framework-ul)
DBAL de sine statator, e un wrapper de PDO foarte asemanator in API care mai da niste features, cum ar fi QueryBuilder, Cache, SchemaManager, Migrations

2 Likes