哪个会更好?在本地文本文件或数据库中存储/访问数据?

发布于 2024-09-01 19:26:45 字数 303 浏览 6 评论 0原文

基本上,我仍在开发一个与谜题相关的网站(实际上是微型网站),并且我正在制作一个工具,可以让您输入单词模式(例如“r??n”)并获取所有匹配的单词(在这种情况下:雨、缰绳、废墟等)。我应该将单词存储在本地文本文件(例如words5.txt,其中包含 5 个字母的单词的回车分隔列表)中,还是存储在数据库中(例如表 Words5,它将再次存储 5 个字母的单词) )?

我正在研究数据检索速度和 CPU 服务器负载方面的问题。我绝对可以尝试这两种方法,并记录使用这两种方法进行几次运行所花费的时间,但我宁愿从可能有这方面经验的人那里听到它。

总体而言哪种方法更好?

Basically, I'm still working on a puzzle-related website (micro-site really), and I'm making a tool that lets you input a word pattern (e.g. "r??n") and get all the matching words (in this case: rain, rein, ruin, etc.). Should I store the words in local text files (such as words5.txt, which would have a return-delimited list of 5-letter words), or in a database (such as the table Words5, which would again store 5-letter words)?

I'm looking at the problem in terms of data retrieval speeds and CPU server load. I could definitely try it both ways and record the times taken for several runs with both methods, but I'd rather hear it from people who might have had experience with this.

Which method is generally better overall?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

零時差 2024-09-08 19:26:45

该数据库将以最少的工作量为您提供最佳的性能。内置的索引支持和查询分析器将为您免费提供良好的性能,而文本文件可能为您提供大量工作的出色性能。

在短期内,我建议创建一个通用接口,它将隐藏数据库和平面文件之间的差异。稍后,您可以对哪个数据库提供最佳性能进行基准测试,但我认为该数据库将为您每小时的开发带来最大的好处。

The database will give you the best performance with the least amount of work. The built in index support and query analyzers will give you good performance for free while a textfile might give you excellent performance for a ton of work.

In the short term, I'd recommend creating a generic interface which would hide the difference between a database and a flat-file. Later on, you can benchmark which one will provide the best performance but I think the database will give you the best bang per hour of development.

爱,才寂寞 2024-09-08 19:26:45

为了快速检索,您当然需要某种索引。如果您不想自己编写索引代码,那么使用数据库当然是最简单的。

如果您的应用程序使用 Java 或 .NET,请考虑查看 db4o。它仅使用一行代码按原样存储任何对象,并且创建表没有任何设置成本。

For fast retrieval you certainly want some kind of index. If you don't want to write index code yourself, it's certainly easiest to use a database.

If you are using Java or .NET for your app, consider looking into db4o. It just stores any object as is with a single line of code and there are no setup costs for creating tables.

习ぎ惯性依靠 2024-09-08 19:26:45

将数据存储在本地文本文件中(当您将新记录添加到文件末尾时)总是比存储在数据库中更快。因此,如果您创建高负载应用程序,您可以将数据保存在文本文件中,然后将数据复制到数据库中。然而,在大多数应用程序中,您应该使用数据库而不是文本文件,因为数据库方法有很多好处。

Storing data in a local text file (when you add new records to end of the file) always faster then storing in database. So, if you create high load application, you can save the data in a text file and copy data to a database later. However in most application you should use a database instead of text file, because database approach has many benefits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文