各种Android ORM框架的性能比较

网友投稿 907 2022-10-23

各种Android ORM框架的性能比较

各种Android ORM框架的性能比较

Performance comparison of Android ORM Frameworks

At the moment there are a lot of ORM-libraries for the Android OS. We reviewed the most popular ones and compared them by performance and some other parameters. As libraries for comparison, the most popular solutions at the time of writing were chosen: ORMLite, Sugar ORM, Freezer, DBFlow, requery, GreenDAO, ActiveAndroid, Room, Sprinkles. Also in the comparison participated "clean" SQLite - the built-in API for working with SQLite in Android, without the use of ORM, and the popular NoSql solution - Realm.

We considered 3 variants(simple, complex, balanced), and for each of them 4 operations(CRUD).

Models

public class Library{ String address; String name;}public class Book{ String author; String title; int pagesCount; int bookId; Library library;}public class Person{ String firstName; String secondName; Date birthdayDate; String gender; long phone; Library library;}

Test cases

Simple - 1 Library object per 1000 Book objectsComplex - 1 Library object for 500 Book objects and 400 Person objects (5 Libraries, 2500 Books, 2000 Persons)Balanced - 1 Library object for 50 Book objects and 50 Person objects (50 Libraries, 2500 Books, 2500 Persons)

Results Table

Librarywrite(s)read(s)update(s)delete(s)write(c)read(c)update(c)delete(c)write(b)read(b)update(b)delete(b)
ORMLite151666122105445383685781115633426724728
SugarORM24584225215214024129146710032204439717021197
Freezer248543024047971337789822221221043255134942188729515
DBFlow977574591863603534312410441129465352041268
Requery871501147129461805786180213688002886763
Realm15129107972369868819666918015222102112910006
GreenDAO8112381179735755524552745985905504315
ActiveAndroid31239302293242314671416515958130231721346531930314642
Sprinkles576610506364605259784334655792428277744526377052519
Room131699170109562320171740313303532790507
SQLite504366380386215519228411462313213318

Histograms

Overal

More detailed (Simple)

More detailed (Complex)

More detailed (Balanced)

Summary

ORMLite

It does not save much from the boilerplate code, however one of the fastest libraries out there is built-in caching and delayed initialization, good documentation. Despite all the advantages, I would not use it, because The main reason for using ORM is getting rid of writing repetitive code, and, therefore, speeding up development, which in other libraries is realized, in my opinion, better.

SugarORM

Of the advantages can be noted ease of use, which is not enough in ORMLite, and that's it. Has a separate drawback associated with the approach to implementation - it is not "friendly" with Instant Run, so when working with it you have to disable it.

Freezer

A relatively young library is not widely distributed. Comfortable, but do not make any complicated manipulations with it. In addition, the speed of work, to put it mildly, leaves much to be desired.

DBFlow

One of the best in the parameters outlined in this article. One of the fastest write / read operations is the average update / delete speed. According to the parameters presented in Table 2, it is the best on a par with Realm. In my opinion, is one of the best alternatives.

Requery

Quite a controversial decision, in the fall because of problems with installation and documentation (if used without RXJava). If you understand, working with it becomes convenient. Supports different databases, rich functionality.

Realm

A relatively fast and convenient library, all links are simply implemented, which is related to the object orientation of the database, even reading "clean" SQLite even when manually cached for it by reading. Excellent documentation. Is, perhaps, one of the best option for storing data on a mobile device at the moment, the minus can only be an increase in the size of the apk-file by 2.5 MB. For all ORMs, except for Realm, built-in object caching was disabled, hence the readings.

GreenDao

It is flexible and convenient to use one-to-many communication, but very unpleasant code generation, as a result of which your classes will be filled with a bunch of methods and comments. In addition, you need to connect the Gradle plug-in, which greatly increases the build time. Also, developers presented their database - ObjectBox - object database, which they position as the fastest, comparable to GreenDao, ORM.

ActiveAndroid

Not very fast, but quite convenient and proven over time solution. Quite popular, but because you can find many articles, solutions to issues and other things, which reduces the appearance of "unresolvable" problems to a minimum.

Sprinkles

Each entry is accompanied by an unnecessary sample (SELECT * FROM% s WHERE% s LIMIT 1). From sql-requests too does not rescue. Performance indicators are the worst of the submitted. Therefore, there is no reason to use it for your projects.

Room

An interesting solution presented on Google I / O 2017 as optimal for working with the database on Android OS. Despite the fact that it is necessary to use explicit sql-requests, the library turned out to be quite convenient and I liked it personally. On performance is in the lead, so I would advise you to choose this particular library. Since this solution, submitted by Google, it will quickly become popular, and, therefore, there will be no problems with finding solutions to problems that occur along with it.

SQLite

A lot of code, longer in time, but speed and flexibility are still unmatched.

Сonclusion

Summing up, the most "fast" ORMs were Realm, GreenDAO, ORMLite and Room, but if performance is critical for the project, a "clean" SQLite with a custom cache is still the best choice. On the other parameters, the best are Realm, DBFlow and GreenDAO. Thus, for small projects and projects of medium complexity, I recommend using DBFlow or GreenDAO, if the size of apk is not important - Realm. Realm and Room are suitable for large projects. And only if their capabilities for some reason are not enough, or the ORM-approach is not for you, to return to using the built-in API for SQLite.

In addition to those discussed in the article, initially ORMs such as AndrORM, OHibernate, MemoryORM, ORMDroid, StromIO were also involved in the review, which were dropped for one reason or another.

All measurements were made on the Samsung S7 device.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:分布式前修课:Redis实现分布式锁
下一篇:#yyds干货盘点# leetcode算法题:二分查找
相关文章

 发表评论

暂时没有评论,来抢沙发吧~