So this morning I ran a test between this 2 methods of reading a file. The script I used to run is at http://thephpcode.pastebin.com/f2e84fab1
So here's the result from the tests of 5 runs:
| fread() (seconds) | file_get_contents() (seconds) | |
|---|---|---|
| Mean | 0.03674 | 0.01322 |
| Min | 0.030710935592651 | 0.0098111629486084 |
| Max | 0.04555082321167 | 0.016166925430298 |
So here it's clear that file_get_contents() is much faster than fread(), mainly because fread() consists of an overhead additional loop and several functions.


0 programmer comments:
Post a Comment