GLe*_*Lee 26 performance android sharedpreferences
速度有多快SharedPreferences?有没有办法把它们放在记忆中供阅读?我有少量数据ListView需要查询以显示每个单元格,我担心对闪存的调用会太慢.我并不担心写入速度,因为写入很少发生.我正在考虑使用JSON对象来保存数据而不是SharedPreferences.有什么想法吗?
Com*_*are 51
有没有办法把它们放在记忆中供阅读?
在第一次参考之后,它们在记忆中.第一次检索特定的SharedPreferences(例如PreferenceManager.getDefaultSharedPreferences())时,数据从磁盘加载并保留.
Joe*_*lin 15
我的建议是首先测试你的表现,然后开始担心速度.一般来说,您会对使用可维护性和速度优先的应用感到满意.当工程师在应用程序稳定之前开始实现性能时,结果是应用程序运行速度更快但有很多错误.
根据这个链接,getSharedPreferences没有那么重,因为它只在你getSharedPreferences第一次打电话时打开文件:
// There are 1000 String values in preferences
SharedPreferences first = context.getSharedPreferences("com.example.app", Context.MODE_PRIVATE);
// call time = 4 milliseconds
SharedPreferences second = context.getSharedPreferences("com.example.app", Context.MODE_PRIVATE);
// call time = 0 milliseconds
SharedPreferences third = context.getSharedPreferences("com.example.app", Context.MODE_PRIVATE);
// call time = 0 milliseconds
Run Code Online (Sandbox Code Playgroud)
但是get第一次使用方法需要一些时间:
first.getString("key", null)
// call time = 147 milliseconds
first.getString("key", null)
// call time = 0 milliseconds
second.getString("key", null)
// call time = 0 milliseconds
third.getString("key", null)
// call time = 0 milliseconds
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9571 次 |
| 最近记录: |