32

I've been using ORMLite in my application and I was considering whether to move to greenDAO.

Performance is a huge part of that decision, and greenDAO's Features page says:

For the same given entity, greenDAO inserts and updates entities over 2 times faster, and loads entities 4.5 times faster for loading entities than ORMLite.
...
(Figures and chart updated 10-23-2011)

I thought ORMLite's config file generation step should remove the need for reflection at runtime.

The ORMLite changlog suggests that the greenDAO benchmark was done after the config file feature was released, but the greenDAO features page doesn't explicitly say if a static config file was generated for the test.

4.26: 9/26/2011 (svn r1978)
* ANDROID: Added field configuration utility to avoid Dao creation performance problems with annotations.

There have also been ORMLite performance fixes since then, e.g.

4.40: 4/16/2012 (svn r2516)
* ANDROID: Big performance bug fix when creating DAOs. Foreign fields always used reflection instead of table configs.

Can anybody confirm if there is still a big performance difference between greenDAO and ORMLite? Thanks!

Dan J
  • 25,433
  • 17
  • 100
  • 173
  • I expect GreenDao to be faster but I'm curious at the latest real numbers. – Gray Nov 19 '13 at 18:49
  • 1
    If speed is your concern, why use an ORM at all? – Alex Fu Dec 10 '13 at 14:25
  • @AlexFu Why would using an ORM degrade speed? If anything, developers may potentially write sloppy code via a ContentProvider or a CursorLoader, which wouldn't make things faster. – IgorGanapolsky Dec 10 '13 at 21:10
  • 1
    @IgorGanapolsky ORMs tend to have added overhead because of the added layers of abstraction. Querying the database directly and consuming that data directly will be faster. By how much? Probably not much but still. Also, if you're developing on Android, you should definitely know how to properly query a ContentProvider or a database... – Alex Fu Dec 11 '13 at 01:18

1 Answers1

65

We've just published a Github project that we used to compare the performance of ORMLite and GreenDao to raw SQLite:
https://github.com/daj/android-orm-benchmark

The project also allows you to compare the performance of an in-memory database to an on disk one.

The headline results are:

GreenDao is much faster than ORMLite. It is roughly:

  • 3X faster at writing large numbers of objects.
  • 50% faster at reading in all 10000 entries in a single table.
  • 2X to 3X faster at an indexed read of a single row (though both were very fast).
  • 15X faster at doing a LIKE search for 100 records in a 10000 entry table.

The project contains both a naive raw SQLite benchmark, and an optimized SQLite benchmark.

GreenDao vs unoptimized raw SQLite

  • GreenDao is 2X faster for the write benchmark.
  • GreenDao is 25% slower for the read benchmark.

GreenDao vs optimized raw SQLite

  • GreenDao is 50% slower for the read and write benchmarks.

For detailed results please see the Github repository above.

Of course we may have bugs in our benchmarking code...if you find any please fork, fix and submit a pull request! :-)

Disclaimer: make sure you do your own research before choosing GreenDao over ORMLite.

Dan J
  • 25,433
  • 17
  • 100
  • 173
  • 1
    Is there also a benchmark comparison of other libraries, like SugarOrm ? – android developer Feb 20 '14 at 11:36
  • 4
    Nope, but feel free to fork the project and add one :-) – Dan J Feb 20 '14 at 17:32
  • OrmLite can use batch queries, btw. It would be interesting to see benchmarks with them – naixx Apr 24 '14 at 17:02
  • 4
    I ran some tests with the benchmark. Its the 1-Many association to readers that makes this slow. When you strip that, reading is roughly 2x, although I'd need to really play with this more to confirm. I have to look at what ormlite is doing with the association, but its set to eager=true, which means it grabs all that data for each row. The green dao test, and the sql test, aren't doing this, so its not a fair comparison. Full disclosure, for what its worth, I did a good chunk of the original ormlite port for android. Nothing in core, though, so I need to do some digging. – Kevin Galligan May 27 '14 at 04:56
  • 2
    Tried to edit but ran out of time. I made some tweaks, and the last test showed reads and writes were 50% slower on ormlite than green. 50% is significant, but its nowhere near 1200% of the green time. I forked the benchmark here: https://github.com/touchlab/android-orm-benchmark I'm going to do more tests, and I'm also working on a precompiled query tool for ormlite. Its a good package, but there are some things that could be improved. Even with eager set to false, the query was slow. That kind of thing. – Kevin Galligan May 27 '14 at 05:18
  • "In fact, GreenDao is actually faster than our raw SQLite" LMAO – Bitcoin Cash - ADA enthusiast Oct 23 '14 at 09:08
  • 1
    I can`t understand how GreenDao can be faster than raw SQL when it is build upon the raw SQL. maybe there is bed optimization in raw sql. – Roman Nazarevych Apr 27 '15 at 12:28
  • FYI, somebody has kindly created a pull request with optimized raw SQL that performs 2-3x better for writes than the original raw SQL: https://github.com/daj/android-orm-benchmark/pull/2 I plan to merge it once we've finished code review. – Dan J Apr 27 '15 at 18:09
  • BTW, did you compare GreenDAO and ORMLite with JDO and Hibernate? – WebComer May 17 '15 at 03:22
  • No, I was investigating for use on Android. – Dan J May 18 '15 at 18:39
  • 1
    The issue with this question is that GreenDao has extremely limited functionality, and it is hard to extend models. I ended up making my own query builder and some raw queries to work around GreenDao limitations and bugs, also some things are slower with GreenDao. I spend more time working around GreenDao than using it. Their documentation is also useless for the most part – Xeridea Jul 01 '15 at 19:31
  • 1
    i made my own tests where ormlite and greendao write speeds are the same, and read speed twice faster on ormlite. greendao only fast when you dont use foreign collections... – deviant Oct 13 '15 at 22:13