Benchmarks comparing 6 approaches to inserting 1 million rows into a MySQL database using Laravel, including Eloquent, factories, query builder, raw DB insert, and bulk native file loading. Key findings: bulk native (LOAD DATA INFILE) is fastest at ~5.5 seconds, while plain Eloquent is slowest due to per-row overhead like password hashing and timestamp generation. Factories are significantly faster than Eloquent for users because they hash the password only once. Query builder and raw DB insert achieve ~100,000 rows/second vs ~4,000 for factories. Also covers a streaming/chunked approach to minimize RAM usage (reducing peak memory from ~560MB to a stable low level) at the cost of slightly slower execution.

9m watch time
1 Comment

Sort: