What would be better? Storage / access to data in a local text file or in a database?

Basically, I'm still working on a puzzle related site (actually, on the micro site itself), and I am creating a tool that allows you to enter a word template (for example, "r ?? n") and get all the relevant words (in this case: rain, occasion, ruins, etc.). Should I store the words in local text files (for example, word5.txt, which will have a list with 5-letter letters with a list) or in a database (for example, in the Words5 table, which again saves 5-letter words)?

I consider the problem in terms of speed of data search and CPU server load. I could definitely try this in both directions and record the time spent on several runs using both methods, but I would rather hear it from people who could have experience with it.

Which method is usually better than the general?

+4
source share
3 answers

For a quick search, you certainly want some kind of index. If you do not want to write index code yourself, this is by far the easiest way to use a database.

If you are using Java or .NET for your application, consider db4o . It simply stores any object as it is with a single line of code, and there is no installation cost to create tables.

+1
source

The database will give you the best performance with the least amount of work. Built-in index analyzers and query analyzers will provide you good performance for free, while a text file can give you excellent performance per ton of work.

In the short term, I recommend creating a common interface that will hide the difference between the database and the flat file. Later you can check which one will provide the best performance, but I think the database will give you the best hit in the hour of development.

+6
source

Saving data in a local text file (when adding new records to the end of the file) is always faster than saving to the database. Thus, if you create a high-load application, you can save the data in a text file and copy the data to the database later. However, in most applications, you should use a database instead of a text file, because a database approach has many advantages.

0
source

Source: https://habr.com/ru/post/1309846/


All Articles