SQLite 与内存
我的应用程序遇到了问题。
假设我有 6 个用户,每个用户最多可以有 9 个分数条目(即晚上 8:00 获得 1000 分,收集金币 3,银币 4 等),即每个阶段和 9 个阶段的分数。
所有这些分数均取自 API 调用,因此可以以 3 分钟以上的间隔更新。
- 我需要对此数据执行的操作是
- 查找第 4 阶段最接近的最小、最大记录。
- 以及更多操作,例如添加或减去两个分数等
所有这 6 个用户及其分数记录已经在数据库中,在 API 调用后需要更新。
现在我的问题是:
对于此类数据(此处为分数数据),将所有 6 个用户的所有数据保存在 NSArray 或 NSDictionary 的内存中,并通过 min- 查找该数组中的最小值和最大值,这是否是更好的方法?最大算法。
或者
应该通过“WHERE Score<=200”和“WHERE Score>=200”之类的查询从数据库中获取,简而言之,2个数据库查询,每个查询返回最近的最小和最大记录,并且不将所有数据保留在记忆。
我们关注的是速度和内存使用情况。关键是,数据库调用是否可以快速有效地查找最小值和最大值,或者在数据库中所有记录的数组中搜索最小值、最大值。 所有记录可以是 6 个用户 * 每条 9 分 = 54。 记录的更新时间可能会超过 3 分钟。 查找某些值的最小值最大值的频率很高。
如果需要更多详细信息,请询问。 提前致谢。
I have a situation with my app.
Suppose I have 6 users, each user can have up to 9 score entries (i.e score 1000 points at 8:00pm with gold collected 3, silver 4 etc etc), say score per stage and 9 stages.
All these scores are being taken from an API call, so it can update with an interval of 3+minutes.
- Operations I need to do on this data is
- find the nearest min, max record from stage 4.
- and some more operations like add or subtract two scores etc
All these 6 users, and their score records are already in database, being updated in needed after the API call.
Now my questions is :
Is this a better way for such kind of data (data of scores here) to keep all the data for all the 6 users in memory in NSArray or NSDictionary, and find min and max in that array by a min-max algorithm.
OR
It should be taken from Database by a query like " WHERE score<=200 " AND " WHERE score >=200", in short, 2 database queries which return nearest min and max record each, and not keeping all the data in memory.
What we are focusing on is speed, and memory usage both. The point is, Would a DB call be fast and efficient to find min and max OR a search for min,max in an Array of all the records from DB.
All records can be 6users * 9scores for each = 54.
Update time for records can be 3+ minutes.
Frequency of finding min max for certain values are high.
Please ask, if any more details are required.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在处理如此少量的数据,我认为不值得担心。采用使您的开发过程最简单的方法!
编辑:
如果我有大量数据(数百个竞争对手),我会使用 SQLite。您可以执行如下查询:
这样您就可以让数据库为您处理计算,这样您就不必获取所有结果。
我的 SQL-fu 并不是最棒的,但我认为你也可以这样做:
这将在一个查询中完成所有计算。
You're working with such a small amount of data that I wouldn't imagine it would be worth worrying about. Do whichever method makes your development process easiest!
Edit:
If I had a lot of data (hundreds of competitors) I'd use SQLite. You can do queries like the following:
That way you can let the database handle doing the calculation for you, so you never have to fetch all the results.
My SQL-fu isn't the most awesome, but I think you can also do this:
That would do all the calculations in one single query.