Reputation: 65
It's a real php interview question. I know the answer is not just which one is faster. We can answer it in many aspects. Can anyone give me some suggestions please?
Upvotes: 1
Views: 181
Reputation: 211590
This is an example of an interview question with no correct answer. A case could be made for either of these things.
For files you might say they're quick to load, that there's a lot of kernel optimization around fetching them from disk and providing them to a user process, and even more around sending them directly from disk to a socket via something like sendfile
. That would be true.
Then for databases you could say that frequently accessed data is stored in memory so there's no I/O round-trip to disk, that could be faster, especially if you're comparing reading parts of a file using a suboptimal structure versus records in a database. This is an algorithmic concern as well.
So it really depends on what kinds of files and what sort of read/write access patterns are involved. To say either of these things is faster is to miss the point of the question.
Upvotes: 1
Reputation: 28722
files:
Database:
Upvotes: 2
Reputation: 415
Reading one file = fast.
Reading many / big files = slow.
Reading singular small entries from database = waste of I/O.
Combining many entries within the database = faster than file accesses.
Upvotes: 0